-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add uniqueIdentifier to storage table #6249
base: production
Are you sure you want to change the base?
Conversation
Did we determine for this whether the users were asking for a user-defined GUID or an auto-filled "real" GUID? like in other tables? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTES:
To force uniqueness on the guid, add uniqueness rule in the schema config
GUID by its very definition must be globally unique, therefore we need to have a non-configurable system uniqueness rule for this
By that same definition, a GUID field should not be self-created as that too breaks (potentially) the GLOBALLY unique characteristic surely. |
Currently, only specify7/specifyweb/businessrules/uniqueness_rules.json Lines 65 to 68 in 0fa890a
If it's a requirement, we can modify the existing specify7/specifyweb/businessrules/rules/guid_rules.py Lines 7 to 16 in 0fa890a
It's not too difficult to search for duplicates within a single table: # Assuming we're in some 'global' signal handler, like set_guids(sender, obj)
duplicates = sender.objects.only('id').filter(guid=obj.guid).exclude(id=obj.id)
if len(duplicates) > 0:
# raise a business rule exception following the expected uniqueness rule signature If GUIDs should always be unique across all tables (e.g., no record should have the same GUID from any other record regardless of table) then things get a little more complicated, but conceptually I think we'd probably want to perform a join across all tables with the guid field (rather than applying the single case across applicable tables, to prevent hitting the database multiple times quickly). |
Is there no uniqueness rule inherently built into the way these are generated? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: #6259 If you feel strongly about this, we could rename this something like "Unique Identifier" instead. That way, it’s clear that we’re aiming for uniqueness within just the storage tree, but we don’t expect these to be unique globally. These identifiers need to be unique within the institution, and really only unique for the storage tree. I'm not sure that these GUIDs are beneficial in any context other than managing the location of physical specimens and for object tracking. Not sure we necessarily need to add logic to ensure that GUIDs are unique outside of specific contexts, such as Collection Object GUID, Taxon GUID, or Storage GUID. The chances of a repeat value appearing among these are very low, especially if they are auto-generated. If duplicates are manually entered between tables for any reason, it’s likely not a major issue, but I understand the concern. From an academic perspective, we would want to maintain the "globally unique" aspect. For now, the bottom line is that we need to ensure that a field intended to be unique is enforced as such. I believe @CarolineDenis's solution is sufficient at this stage, though I welcome a name change if you both feel it is necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing instructions
- Verify the new field GUID is there
- verify you can save without a GUID
- verify you can save with guid
- Verify you cannot save because the GUID is not unique
Migrations all good:
~/GitHub/specify7 on issue-6247 = !8 ❯ docker exec -it specify7-specify7-1 /bin/bash at 08:48:11 PM
specify@2cf30bc205b3:/opt/specify7$ ve/bin/python manage.py migrate businessrules 0005
[20/Feb/2025 02:48:54] [ERROR] [specifyweb.attachment_gw.views:237] Bad attachment key.
Operations to perform:
Target specific migration: 0005_cojo, from businessrules
Running migrations:
Rendering model states... DONE
Unapplying businessrules.0006_storage_guid... OK
specify@2cf30bc205b3:/opt/specify7$ ve/bin/python manage.py migrate specify 0023
[20/Feb/2025 02:49:26] [ERROR] [specifyweb.attachment_gw.views:237] Bad attachment key.
Operations to perform:
Target specific migration: 0023_update_schema_config_text, from specify
Running migrations:
Rendering model states... DONE
Unapplying specify.0024_add_guid_storage... OK
specify@2cf30bc205b3:/opt/specify7$
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requirement were updated during the usability meeting, will re-review once the field name changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Verify the new field GUID is there
- verify you can save without a GUID
- verify you can save with guid
- Verify you cannot save because the GUID is not unique
Looks good! Everything is functional, and GUID is now named uniqueIdentifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #6247
Warning
This PR affects database migrations. See migration testing instructions.
Checklist
self-explanatory (or properly documented)
Testing instructions