specify / specify7

Specify 7
https://www.specifysoftware.org/products/specify-7/
GNU General Public License v2.0
65 stars 36 forks source link

catalog number regex formatter containing a comma prevents auto-detection as delimiter #4122

Open bronwyncombs opened 12 months ago

bronwyncombs commented 12 months ago

From CSIRO:

This is not at all urgent. We have a workaround, flagging for FYI. We get an error when creating loans by pasting comma-delimited lists of catalog numbers into the entry box:

image

The catalog numbers do meet the required format, and paste fine into the query builder as a comma-delimited list. Also, we have no issue creating the loan with the same numbers as a list straight from excel, with a new line as the delimiter: image

Additionally, if I go into user preferences, and specifically change my Interactions preference to 'Use' for 'Use comma as delimiter' (as opposed to 'Determine automatically'), Specify then happily accepts my comma delimited list and goes to next window. image image image

To Reproduce This is how the catalog number format is defined:

<format system="false" name="CatalogNumberAnwcTissues" class="edu.ku.brc.specify.datamodel.CollectionObject" fieldname="catalogNumber">
     <field type="regex" value="(G[0-9]{1,5})" size="9" minsize="2" pattern="G#####"/>
  </format>

The comma in (G[0-9]{1,5}) prevents it from accepting a comma when the preference is set to automatically detect delimiters.

melton-jason commented 12 months ago

For developer future reference, this is most likely happening because of the useParser() hook in */lib/components/Interactions/InteractionDialog.tsx

https://github.com/specify/specify7/blob/5ddf62fc57a579ac3db5878b6c187d4c7617b884/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx#L374-L443

More specifically because it fetches the value of every value attribute in a formatter and checks whether the delimiter is included.

https://github.com/specify/specify7/blob/5ddf62fc57a579ac3db5878b6c187d4c7617b884/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx#L403-L408

Thus when the useCommaAsDelimiter preference is set to auto, this specific regular expression will never use comma as a delimiter because Specify thinks that the formatter itself has a comma.

https://github.com/specify/specify7/blob/5ddf62fc57a579ac3db5878b6c187d4c7617b884/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx#L418-L421

melton-jason commented 12 months ago

If CSIRO wishes to have the useCommaAsDelimiter preference set to 'auto' before this bug is fixed, they can replace the value attribute of the CatalogNumberAnwcTissues formatter in their UIFormatters to an equivalent regular expression which does not use commas.

I have found, tested, and thus verified through Data Entry, QueryBuilder, and Workbench, one such equivalent regular expression which does not utilize commas. (G[0-9]?[0-9]?[0-9]?[0-9]?[0-9])

CarolineDenis commented 10 months ago

@melton-jason, can this be closed?

melton-jason commented 10 months ago

As far as I know, the actual bug has not been fixed.

In brief (explained further in https://github.com/specify/specify7/issues/4122#issuecomment-1765376026), the problem was that when useCommaAsDelimiter was set to auto, Specify would never use a comma as delimeter if the UIFormatter for the field contained a comma in it's value.

This is well intentioned, but was not taking into account regular expression formatters: whose value is the regular expression itself and thus may commonly contain commas even though the actual expected value of the field may not.