Skip to content

Don't crash on non-traditional external field formats#7179

Merged
CarolineDenis merged 16 commits into
mainfrom
issue-7144
Jul 24, 2025
Merged

Don't crash on non-traditional external field formats#7179
CarolineDenis merged 16 commits into
mainfrom
issue-7144

Conversation

@melton-jason
Copy link
Copy Markdown
Contributor

@melton-jason melton-jason commented Jul 23, 2025

Fixes #7144

As alluded to by @alesan99 in #7144 (comment), the primary underlying cause of #7144 was a change in #6710 for handling the case where a Field Formatter for CollectionObject -> catalogNumber did not exist.

This was mainly caused in the following line where a non-null assertion operator (!) was used to tell the TypeScript compiler that the value couldn't be null (even when it could be null).

This would largely be the case when the CollectionObject catalogNumber format was defined as an external format and was not the known CatalogNumberNumeric format

if (typeof formatter.external === 'string') {
if (
parseJavaClassName(formatter.external) ===
'CatalogNumberUIFieldFormatter'
)
resolvedFormatter = new CatalogNumberNumeric();
else return undefined;

In the default field formatters, this would be the case for the CatalogNumberString format

<format system="true" name="CatalogNumberString" class="edu.ku.brc.specify.datamodel.CollectionObject" fieldname="catalogNumber" default="false">
<external>edu.ku.brc.specify.ui.CatalogNumberStringUIFieldFormatter</external>
</format>

This PR handles the case where a CollectionObject -> catalogNumber is not defined, as well as does some refactoring/maintenance work to extract the BulkCarry logic to its own components.

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add relevant issue to release milestone
  • Add pr to documentation list
  • Add automated tests
  • Add a reverse migration if a migration is present in the PR

Testing instructions

Test series entry (instructions take from #6710 (comment))

  • Go to Data Entry for Collection Object
  • Click on Form Meta and enable Carry Forward and Bulk Carry Forward Range. Also enable "create record set"
  • Fill out some fields on the form and save.
  • The Carry Forward range input should appear
  • Make sure you can only enter a valid start catalog number (It should use the catalog num of the CO you just saved)
  • Make sure you can only enter a valid end catalog number
  • Make sure you can't enter invalid ranges (where the start is bigger than the end for example)
  • Make sure you can't enter a range with 500 or more records.
  • Click Carry Forward and make sure all the COs in the range you specified were created
  • Try to Carry Forward over catalog numbers belonging to COs that already exist
  • Click Carry Forward and see a dialog with a list of all existing catalog numbers.
  • Click on Form Meta and disable the "create record set on bulk carry" preference
  • Try Bulk Carry Forward and make sure no record set is created. But make sure all newly created records appear on the form page thing.
  • Try creating a CO with a Collection Object Type with that uses a different formatter for the catalog number. Bulk Carry should still work, except if the formatter does not support autoincrementing (the button will be disabled).

  • Set the CatalogNumberFormatName on the Collection or (default CollectionObjectType) to be a CollectionObject -> catalogNumber Field Format which includes an external tag with any value besides edu.ku.brc.specify.ui.CatalogNumberUIFieldFormatter.
    • You can use the default CatalogNumberString format:

<format system="true" name="CatalogNumberString" class="edu.ku.brc.specify.datamodel.CollectionObject" fieldname="catalogNumber" default="false">
<external>edu.ku.brc.specify.ui.CatalogNumberStringUIFieldFormatter</external>
</format>

  • Ensure that the CollectionObject form can be opened

  • Enable the Show Bulk Carry Forward range preference in the CollectionObject's Form Meta menu

  • Ensure the series-entry, Bulk Carry Forward range box does not appear on the form and you can not use the BulkCarryForward range feature

  • Enable the Show Bulk Carry Forward count preference in the CollectionObject's Form Meta menu

  • Ensure the Bulk Carry Forward count number input does not appear on the form and you can not use the BulkCarryForward count feature

  • Please also do some general testing regarding Carry Forward and the BulkCarryForward configuration options!

    • Particularly, can cloning COGs be tested? As well as CollectionObjects in COGs. Ensure there are no regressions!

@melton-jason melton-jason added this to the 7.11.1 milestone Jul 23, 2025
@melton-jason melton-jason requested review from a team and alesan99 July 23, 2025 05:28
@github-project-automation github-project-automation Bot moved this to 📋Back Log in General Tester Board Jul 23, 2025
Copy link
Copy Markdown
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The Carry Forward range input should appear
  • Make sure you can only enter a valid start catalog number (It should use the catalog num of the CO you just saved)
  • Make sure you can only enter a valid end catalog number
  • Make sure you can't enter invalid ranges (where the start is bigger than the end for example)
  • Make sure you can't enter a range with 500 or more records.
  • Click Carry Forward and make sure all the COs in the range you specified were created
  • Click Carry Forward and see a dialog with a list of all existing catalog numbers.
  • Try Bulk Carry Forward and make sure no record set is created. But make sure all newly created records appear on the form page thing.
  • Try creating a CO with a Collection Object Type with that uses a different formatter for the catalog number. Bulk Carry should still work, except if the formatter does not support autoincrementing (the button will be disabled).

  • Ensure that the CollectionObject form can be opened

  • Ensure the series-entry, Bulk Carry Forward range box does not appear on the form and you can not use the BulkCarryForward range feature

  • Enable the Show Bulk Carry Forward count preference in the CollectionObject's Form Meta menu

  • Ensure the Bulk Carry Forward count number input does not appear on the form and you can not use the BulkCarryForward count feature

  • Please also do some general testing regarding Carry Forward and the BulkCarryForward configuration options!

    • Particularly, can cloning COGs be tested? As well as CollectionObjects in COGs. Ensure there are no regressions!

  • When I first loaded up an instance both count and range were selected but when I deselected one it fixed itself so I am not sure what happened. Might not be a problem since I can't recreate it but I wanted to mention it here just in case.
Screenshot 2025-07-23 081305
  • In main on COGs the checkboxes for showing clone and carry forward on the form are all there but checking them doesn't do anything whereas on this branch the checks are just not visible. Was this intentional? Also if it was, the checkbox for showing the 'Add' button needs to be visible as that one should be configurable, I think hiding the checkboxes for showing clone and carry forward makes sense since they don't work for COGs anyway.

Main:
image

issue branch:
image

@github-project-automation github-project-automation Bot moved this from 📋Back Log to Dev Attention Needed in General Tester Board Jul 23, 2025
@melton-jason
Copy link
Copy Markdown
Contributor Author

  • When I first loaded up an instance both count and range were selected but when I deselected one it fixed itself so I am not sure what happened. Might not be a problem since I can't recreate it but I wanted to mention it here just in case.
Screenshot 2025-07-23 081305

Hmmm, technically both count and range can be selected at the same time. You can always recreate this behavior by manually editing the User Preferences such that count and range are both enabled for the table.
In the case that both are enabled for a particular table and you are viewing an existing CollectionObject, Specify will prioritize showing the range input over the count input.

Not sure how this behavior was initially introduced on your instance.

  • In main on COGs the checkboxes for showing clone and carry forward on the form are all there but checking them doesn't do anything whereas on this branch the checks are just not visible. Was this intentional? Also if it was, the checkbox for showing the 'Add' button needs to be visible as that one should be configurable, I think hiding the checkboxes for showing clone and carry forward makes sense since they don't work for COGs anyway.

Main:
image

issue branch:
image

Hiding the clone and carry forward checkboxes in the FormMeta wasn't explicitly intentional, but if the behavior is more intuitive then I would be fine to keep it.

Some of the testing for COGs and cloning would be testing cloning records which aren't COGs but have related COGs: such as cloning CollectionObjects which have COGs and ensuring there is no regression in the behavior compared to main/v7.11.0.2

@melton-jason melton-jason requested a review from emenslin July 23, 2025 19:02
Copy link
Copy Markdown
Contributor

@alesan99 alesan99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The Carry Forward range input should appear
  • Make sure you can only enter a valid start catalog number (It should use the catalog num of the CO you just saved)
  • Make sure you can only enter a valid end catalog number
  • Make sure you can't enter invalid ranges (where the start is bigger than the end for example)
  • Make sure you can't enter a range with 500 or more records.
  • Click Carry Forward and make sure all the COs in the range you specified were created
  • Click Carry Forward and see a dialog with a list of all existing catalog numbers.
  • Try Bulk Carry Forward and make sure no record set is created. But make sure all newly created records appear on the form page thing.
  • Try creating a CO with a Collection Object Type with that uses a different formatter for the catalog number. Bulk Carry should still work, except if the formatter does not support autoincrementing (the button will be disabled).
  • Ensure that the CollectionObject form can be opened
  • Enable the Show Bulk Carry Forward range preference in the CollectionObject's Form Meta menu
  • Ensure the series-entry, Bulk Carry Forward range box does not appear on the form and you can not use the BulkCarryForward range feature
  • Enable the Show Bulk Carry Forward count preference in the CollectionObject's Form Meta menu
  • Ensure the Bulk Carry Forward count number input does not appear on the form and you can not use the BulkCarryForward count feature
  • Please also do some general testing regarding Carry Forward and the BulkCarryForward configuration options!

Using CatalogNumberString as the collection default no longer crashes, as well as using it as the COT formatter.

Tried cloning COs within a COG, looks like its working correctly except isPrimary misassigned, but that is not a regression 👍

The Add button also appears on COG forms now as expected.
chrome_AG3e3YEDV5

And the issue I was having with existing catalog numbers causing a crash has been fixed 👍👍

Copy link
Copy Markdown
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The Carry Forward range input should appear
  • Make sure you can only enter a valid start catalog number (It should use the catalog num of the CO you just saved)
  • Make sure you can only enter a valid end catalog number
  • Make sure you can't enter invalid ranges (where the start is bigger than the end for example)
  • Make sure you can't enter a range with 500 or more records.
  • Click Carry Forward and make sure all the COs in the range you specified were created
  • Click Carry Forward and see a dialog with a list of all existing catalog numbers.
  • Try Bulk Carry Forward and make sure no record set is created. But make sure all newly created records appear on the form page thing.
  • Try creating a CO with a Collection Object Type with that uses a different formatter for the catalog number. Bulk Carry should still work, except if the formatter does not support autoincrementing (the button will be disabled).
  • Ensure that the CollectionObject form can be opened
  • Enable the Show Bulk Carry Forward range preference in the CollectionObject's Form Meta menu
  • Ensure the series-entry, Bulk Carry Forward range box does not appear on the form and you can not use the BulkCarryForward range feature
  • Enable the Show Bulk Carry Forward count preference in the CollectionObject's Form Meta menu
  • Ensure the Bulk Carry Forward count number input does not appear on the form and you can not use the BulkCarryForward count feature
  • Please also do some general testing regarding Carry Forward and the BulkCarryForward configuration options!

Looks good, only thing I discovered is I can't bulk carry forward on a CO with a non default COT with a different catalog number format.

07-23_15.52.mp4

Specify 7 Crash Report - 2025-07-23T20_52_22.360Z.txt

Link to the db: https://ojsmnh20250717-issue-7144.test.specifysystems.org/specify/

@CarolineDenis CarolineDenis requested a review from emenslin July 24, 2025 14:21
@alesan99
Copy link
Copy Markdown
Contributor

alesan99 commented Jul 24, 2025

Looks good, only thing I discovered is I can't bulk carry forward on a CO with a non default COT with a different catalog number format.

@emenslin I managed to recreate it on your instance a couple times, then it looks like it fixed itself? Very strange.
To add, apparently a similar configuration (######### to YEAR-######) work on KUBirds and csi so I'm not sure what the issue is.
So it looks like there was some other underlying issue, but if its possible to recreate again I'd like to address it.

Update:
Seems to be caused by existing COs with invalid catalog numbers (blanks). These appear to automatically fallback to ######### as per the existing autonumber logic. Creating enough new valid COs fixes it.
image

@CarolineDenis CarolineDenis requested a review from acwhite211 July 24, 2025 14:52
@emenslin
Copy link
Copy Markdown
Collaborator

emenslin commented Jul 24, 2025

I believe I have discovered the problem. It seems to have to do with having no fields selected in the configuration for bulk carry forward. I'm not sure why this is because you cannot deselect 'type' in the config so there is probably some other field in there that is causing the problem but I am not sure which

07-24_10.11.mp4

Wrote up #7197

Disable Series Data Entry when 'isCurrent' and 'isPrimary' can be misassigned
Triggered by 1c9d603 on branch refs/heads/issue-7144
@alesan99
Copy link
Copy Markdown
Contributor

alesan99 commented Jul 24, 2025

I believe I have discovered the problem. It seems to have to do with having no fields selected in the configuration for bulk carry forward. I'm not sure why this is because you cannot deselect 'type' in the config so there is probably some other field in there that is causing the problem but I am not sure which

@emenslin It appears deselect all is deselecting required fields, even though they still appear checked.
I verified this by manually selecting everything, and still seeing the error. Clicking select all fixed it.

So the issue probably happens with 1. a non default formatter 2. Some invalid records (maybe) 3. the user click deselct all in the settings.

This is an existing issue that affects Bulk Carry Forward Count, though it should be written up.

Copy link
Copy Markdown
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The Carry Forward range input should appear

  • Make sure you can only enter a valid start catalog number (It should use the catalog num of the CO you just saved)

  • Make sure you can only enter a valid end catalog number

  • Make sure you can't enter invalid ranges (where the start is bigger than the end for example)

  • Make sure you can't enter a range with 500 or more records.

  • Click Carry Forward and make sure all the COs in the range you specified were created

  • Click Carry Forward and see a dialog with a list of all existing catalog numbers.

  • Try Bulk Carry Forward and make sure no record set is created. But make sure all newly created records appear on the form page thing.

  • Try creating a CO with a Collection Object Type with that uses a different formatter for the catalog number. Bulk Carry should still work, except if the formatter does not support autoincrementing (the button will be disabled).

  • Ensure that the CollectionObject form can be opened

  • Ensure the series-entry, Bulk Carry Forward range box does not appear on the form and you can not use the BulkCarryForward range feature

  • Enable the Show Bulk Carry Forward count preference in the CollectionObject's Form Meta menu

  • Ensure the Bulk Carry Forward count number input does not appear on the form and you can not use the BulkCarryForward count feature

  • Please also do some general testing regarding Carry Forward and the BulkCarryForward configuration options!

    • Particularly, can cloning COGs be tested? As well as CollectionObjects in COGs. Ensure there are no regressions!

Looks good, I didn't run into any new issues.

@emenslin emenslin requested a review from a team July 24, 2025 16:50
@CarolineDenis CarolineDenis merged commit 9be61a5 into main Jul 24, 2025
14 checks passed
@CarolineDenis CarolineDenis deleted the issue-7144 branch July 24, 2025 17:26
@github-project-automation github-project-automation Bot moved this from Dev Attention Needed to ✅Done in General Tester Board Jul 24, 2025
grantfitzsimmons pushed a commit that referenced this pull request Sep 4, 2025
Don't crash on non-traditional external field formats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅Done

Development

Successfully merging this pull request may close these issues.

Cannot read properties of undefined (reading 'canAutoIncrement') when opening any form

5 participants