-
Notifications
You must be signed in to change notification settings - Fork 18
Fix propagation of embargoed date from dandisets to assets #2698
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
base: master
Are you sure you want to change the base?
Fix propagation of embargoed date from dandisets to assets #2698
Conversation
|
@h-mayorquin I think it broke tests -- do they pass for you locally? copilot's take on itThe failing job 60823788006 encountered a KeyError: 'embargoedUntil' when serializing the Solution: Code FixExample for serializer or any place where the field is accessed: embargoed_until = None
access = first_version.metadata.get('access', [])
if access and isinstance(access[0], dict):
embargoed_until = access[0].get('embargoedUntil')
# Use embargoed_until (could be None if not present)If you need the value to always be present, add a default: embargoed_until = access[0].get('embargoedUntil', 'default-value')Alternatively, handle the missing field in your serializer:
Additional suggestion
Summary: |
waxlamp
left a comment
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 understand that this is a small-seeming change that fixes immediate problems, but my alarm bells are ringing at the idea of blindly copying embargo-level metadata from an associated version to the asset itself.
@jjnesbitt, can you assess the longer-term danger here, in case we need to merge this fix in the short term? If we do that, we need to create an issue to look at the deeper problem here and fix at that level.
dandiapi/api/models/asset.py
Outdated
| is_embargoed = self.is_embargoed | ||
| if is_embargoed: | ||
| # Embargo info is only set on the first version's metadata | ||
| first_version = self.versions.first() |
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.
Will this always be correct? We may one day have a model where some versions are embargoed while others are not (although, I admit, this seems unlikely). In a case like that, this would become wrong again.
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 think for the time being the assumption that embargo is a blocker for publishing (that is, embargoed dandisets can only have a draft version) is okay. If that changes, many more places than this will need to be changed anyway.
dandiapi/api/models/asset.py
Outdated
| # Some tests create assets without an associated version | ||
| if first_version: | ||
| embargoed_until = first_version.metadata['access'][0]['embargoedUntil'] | ||
| access['embargoedUntil'] = embargoed_until |
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.
As you pointed out in the associated issue
That said, I am not sure why we have embargoedUntil at the asset level at all since this is only a dandiset parameter.
A better fix would be to take a deeper look at "denormalizing" embargo metadata onto assets as well as Dandisets.
* Fix version retrieval (a simple .first() won't return `draft` if other versions are present) * Factor access logic out into separate method * Raise exception if dandiset is OPEN with an embargoed asset * Don't assume `embargoedUntil` is present on version metadata
Fixes #2697