Problem uploading new media to subjects with existing media
Closed this issue · 0 comments
Problem: When calling Subject.add_location()
for a subject that has already been created and saved (i.e., has ID + existing media locations
entries), new media is not uploaded correctly.
Current Behavior: When initialized (e.g., using Subject.find()
), subjects with existing locations
entries (N_locations > 0) are initialized with an empty _media_files
list (N_mediafiles = 0). When Subject.save()
is executed after adding a new subject image via add_location()
, the uninitialized _media_files
list doesn't match up element-for-element with the locations
array leading to issues in the zip()
call below:
panoptes-python-client/panoptes_client/subject.py
Lines 158 to 161 in c0bc5c2
Furthermore, locations
is not added to modified_attributes
. But even if modified_attributes
is altered manually, the save()
will fail when the mismatch leads to the client trying to PUT to an existing, unwritable location.
Here's an illustrative example:
s = Subject.find(<SUBJECT_ID>)
In [7]: len(s.locations)
Out[7]: 3
In [8]: len(s._media_files)
Out[8]: 0
s.add_location('kitten.jpg')
In [10]: len(s.locations)
Out[10]: 4
In [11]: len(s._media_files)
Out[11]: 1
Desired Behavior: Initialize Subject()
instances with a _media_files
array whose length matches that of locations
array and is filled with None
elements. Also, add locations
to modified_attributes
when add_location
is called. Fixing both of these issues solves upload problem.