-
Notifications
You must be signed in to change notification settings - Fork 27
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 support for SubjectSet metadata as editable attribute #303
Conversation
Subject set tests need updating somewhere to add in metadata.
|
Commenting so I can get emails about progress of this PR (not a rush, just so I don't forget) |
0df5a9f
to
d84e936
Compare
This PR currently has an implementation issue: most SubjectSets do not have any metadata, so therefore metadata == This buggy behavior also exists for subjects (and elsewhere), but hasn't been discovered until now because most other resources have non-empty metadata so never encounter this case. The simple solution would be to always set |
…ified_attributes if diff
Using the same behavior we implemented for SubjectSet, we are removing the else clause that would set _original_metadata to None in favor of allowing init() to set it to an empty dict.
6621d5d
to
230e346
Compare
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.
Changes look ok. I had some questions and comments. Not blocking.
Going off the fact that you and Toyosi have tested your changes and the want for a new version release, changes look fine to merge.
@@ -215,8 +215,6 @@ def set_raw(self, raw, etag=None, loaded=True): | |||
super(Subject, self).set_raw(raw, etag, loaded) | |||
if loaded and self.metadata: | |||
self._original_metadata = deepcopy(self.metadata) | |||
elif loaded: |
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.
OOC, what was the motivation for this change on Subject.py? Is it related to this change (i.e. fixing issue of allowing subject_set metadata to be editable)?
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 used the same pattern related to metadata
and _original_metadata
in the SubjectSet class as is used for the Subject class. Therefore I applied the same fix to Subjects as was used for SubjectSets. We realized that the "how to initialize with empty metadata" issue affected both classes, but hasn't been reported as a bug for Subjects due to the fact that few subjects are created without metadata.
@@ -33,6 +33,7 @@ def test_create(self): | |||
json={ | |||
'subject_sets': { | |||
'display_name': 'Name', | |||
'metadata': {}, |
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.
nitpicky, but we can probably test the case where we want metadata to be updated.
something similar to this but with
subject_set.metadata['indexField'] = some index field
to test the case that is mentioned in issue zooniverse/panoptes-cli#256 broken in cli.
Given the state of python client (and the fact that you and Toyosi have mentioned that you all have tested extensively) , this test I guess is not necessary but would be a nice to have.
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'm crap at writing tests. If you and Toyosi can figure out how to write an appropriate test for the with and without metadata cases, please do go ahead and add. However, I don't consider that a requirement for merging this PR -- the current test is basically a unit test, and the adjustment I made was to reflect how existing resources are loaded.
Closes zooniverse/panoptes-cli#256
The issue: when
SubjectSet.metadata
attribute is edited, there is no check for changes in that field, so it is never added tomodified_attributes
set and therefore those edits were never pushed as a result of thesave()
call.Following same solution as in #222 and #251 for workflow and project attributes:
set_raw
and__init__
functionssave()
to add metadata attribute tomodified_attributes
if contents are differentNote on change in treatment of
SubjectSet.metadata
field: I've changedmetadata
to a standalone key inSubjectSet._edit_attributes
field as opposed to dict similar tolinks
field. The distinction between these two treatments of the attribute occur inPanoptesObject._savable_dict()
(see https://github.com/zooniverse/panoptes-python-client/blob/master/panoptes_client/panoptes.py#L759-L793), but I'm following the precedent already used bySubject
class and elsewhere for these dict attribute fields.Note on CLI issue: although treatment of SubjectSet metadata has been implemented in the CLI for ~2 years (since zooniverse/panoptes-cli#214), it looks like this feature -- identifying and flagging indexed fields by adding them to
indexFields
key in SubjectSet metadata -- has never worked up to this point.This PR currently needs testing: