-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Make UIDReferenceField
to not keep back-references by default
#2219
Changes from 5 commits
99a951f
3e8fc9f
284f75e
4f7b291
f562972
393b450
4149581
be8cd1f
c00a4c8
2740abb
ebd1b92
6616409
d0b6a44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -323,3 +323,38 @@ def migrate_reference_fields(obj, field_names): | |||
|
||||
# Remove this relationship from reference catalog | ||||
ref_tool.deleteReferences(obj, relationship=ref_id) | ||||
|
||||
|
||||
def rename_retestof_relationship(tool): | ||||
"""Renames the relationship for field RetestOf from the format | ||||
'<portal-type>RetestOf' to 'AnalysisRetestOf'. This field is inherited by | ||||
different analysis-like types and since we now assume that if no | ||||
relationship is explicitly set, UIDReferenceField does not keep | ||||
back-references, we need to update the relationship for those objects that | ||||
are not from 'Analysis' portal_type | ||||
""" | ||||
logger.info("Rename RetestOf relationship ...") | ||||
uc = api.get_tool("uid_catalog") | ||||
portal_types = ['DuplicateAnalysis', 'ReferenceAnalysis', 'RejectAnalysis'] | ||||
brains = uc(portal_type=portal_types) | ||||
total = len(brains) | ||||
for num, brain in enumerate(brains): | ||||
if num and num % 100 == 0: | ||||
logger.info("Rename RetestOf relationship {}/{}" | ||||
.format(num, total)) | ||||
|
||||
if num and num % 1000 == 0: | ||||
transaction.savepoint() | ||||
|
||||
# find out if the current analysis is a retest | ||||
obj = api.get_object(brain) | ||||
field = obj.getField("RetestOf") | ||||
retest_of = field.get(obj) | ||||
if retest_of: | ||||
# re-link referenced object | ||||
field.link_reference(retest_of, obj) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens with the existing references in the annotations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing references will be kept:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And the references from the old key? Maybe we can remove it before it get's orphane. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove it yes. |
||||
|
||||
# Flush the object from memory | ||||
obj._p_deactivate() | ||||
|
||||
logger.info("Rename RetestOf relationship [DONE]") |
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.
I don't understand this logic and the docstring.
How can it return
True
if the value isNone
when the first condition checks for strings only and the second condition for falsy values?IMO the check should be smth. like this:
But what should be now actually the desired behavior? As far as I understood it should not be linked unless explicitly set to a relationship key...
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.
Fixed with 4149581 . Sometimes I overthink
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.
Okay, this means per default backrefs are not set. Is this currently only the case for client references in analysisrequest or for other references as well?
Would it make sense to purge the old references from these objects? I think about clients with thousands of samples linked as backreferences.
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.
This applies for all references, regardless of the source/target types. For this PR, I've searched for
get_backreferences
everywhere (add-ons included) to find the cases for which we use backreferences, but without the relationship being set actually. I then assigned the relationships manually to ensure that everything keeps working.Probably. I would expect a reduction of the size of the serialized objects.
Is ok if I open another PR for this purge?Will update the PR in accordance and let you know when ready again