-
Notifications
You must be signed in to change notification settings - Fork 38
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
Expand merging to Localities, Paleo Ctxt, Collecting Event #4606
base: production
Are you sure you want to change the base?
Conversation
Triggered by b62a79b on branch refs/heads/issue-4046
What would be the logical new code? MergeSubviewButton line 52, CompareSubView.tsx () =>
relationshipIsToMany(relationship)
? (resource as SpecifyResource<Accession>).getDependentResource(
relationship.name as 'accessionAgents'
)?.models.length ?? 0
: resource.get(relationship.name) === undefined
? 0
: 1,
[relationship, resource]
); In the code above, relationship is a 'zero-to-one'. export const relationshipIsToMany = (
relationship: Relationship | undefined
): boolean =>
relationship?.type.includes('-to-many') === true ||
relationship?.type === 'zero-to-one'; models.length is now throwing an error for other tables Why do we have zero-to-one being consider as a IsToMany? |
Triggered by 938370d on branch refs/heads/issue-4046
zero-to-one is a "hack" relationship type introduced at some point in sp6 to do a quick fix for some user request, and now we have to live with the consequences (that's why quick fixes aren't a good idea most of the time) But, @realVinayak or @melton-jason might be able to provide a better description that me based on their knowledge of back-end, business rules, databases and sp6 If it becomes really necessary, and we can't infer what zero-to-one means from the back-end code, we could contact Ben to ask him to explain it one more time edit: my messages to Ben about this:
Ben:
See also helpful information in https://specifydev.slack.com/archives/CC6V12D3J/p1617992659051300 Max:
Ben:
|
The assesment @maxpatiiuk provided is correct to my knowledge. There are two I don't think the backend of Specify 7 has any dedicated logic to handling specify7/specifyweb/specify/load_datamodel.py Lines 333 to 336 in 906d739
At a database level, it is indistinguishable from a However, for whatever reason the restriction was needed in Specify 6 to enforce the relationship as a In the Specify 6 code, the relationship was denoted Although, when working with the ORM Specify6 uses (Hibernate), the columns still needed to be mapped as
It seems they were first added in specify/specify6@3126d02, but I can not find any documenttation or reasoning as to why this restriction was needed or desired in the first place. The relationship can be approached conceptually as "A Locality can have zero or one associated LocalityDetail/GeocoordDetail records". |
Triggered by eee4cb4 on branch refs/heads/issue-4046
Thanks for the detailed analysis @melton-jason!
Interesting, because it seems like this could have been represented as an optional one-to-one, unless it has to be different for some reason specific to sp6 codebase |
@melton-jason would it make sense to use the schemaoverwrites files to make sp7 front-end treat this as a -to-one relationship? |
Currently, it would be easiest for the frontend to treat While it would require modifications to both the frontend and backend, It might be easier to treat the relationship as a dependent However, there is a small concern regarding the name of the relationships: |
specifyweb/frontend/js_src/lib/components/Merging/definitions.ts
Outdated
Show resolved
Hide resolved
the current pr patches that for this. see relevant changes |
Triggered by 1437127 on branch refs/heads/issue-4046
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.
small simplification, otherwise looking good
Here is the current unit test to Collecting Event. specify7/specifyweb/specify/api_tests.py Lines 1300 to 1367 in 6400375
@grantfitzsimmons I'm working on getting this working in the record merging code. I've added to the unit test and just want to make sure these are the right test assertions that will show that this problem is solved: # Setup test collectors, where each collector points to the same agent
collector_1 = models.Collector.objects.create(
isprimary=True, ordernumber=1, agent=self.agent, collectingevent=collecting_event_1)
collector_2 = models.Collector.objects.create(
isprimary=True, ordernumber=1, agent=self.agent, collectingevent=collecting_event_2)
collector_3 = models.Collector.objects.create(
isprimary=True, ordernumber=1, agent=self.agent, collectingevent=collecting_event_3)
# ... after the merge request where collecting_event_2 if the old record and collecting_event_1 and collecting_event_3 are the new records.
# Assert that the collectors were updated correctly to the new collecting event.
# Also, assert that remove duplicate collector records with the same agent were deleted.
self.assertEqual(models.Collector.objects.filter(agent=self.agent).count(), 1) # only one collector is left
self.assertEqual(models.Collector.objects.filter(id=collector_1.id).count(), 0) # assert collector_1 does not exist
self.assertEqual(models.Collector.objects.filter(id=collector_2.id).count(), 1) # assert collector_2 still exists
self.assertEqual(models.Collector.objects.filter(id=collector_3.id).count(), 0) # assert collector_3 does not exist |
Hmm, #4606 (comment), wasn't frontend supposed to warn if duplicate collectors were being inserted? should have done so, as part of save blockers (uniqueness rules) |
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.
unit tests + #4940
@grantfitzsimmons, |
Simplify deletion of dependent resources + Move tests
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.
some things that'll be helpful to be clarified.
@acwhite211 see the simplifications 🤷 🤦♂️ . hack wasn't needed after all. didn't change any of the tests you said failed without this hack. also removed the need for the http response (the caller should handle it). |
NOTES: |
that case seems fine. if they aren't exact duplicates, it won't combine them into one. it flags duplicate agents now, so users can pick one. |
Fixes #4046
Checklist
and self-explanatory (or properly documented)
Testing instructions
Utils:
https://discourse.specifysoftware.org/t/shared-vs-embedded-records-configuration/1712/1