-
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
Unable to subject.save simple metadata addition #220
Comments
Even the original code now seems to be working! Close the issue. |
I'm reopening this as I just ran into the same issue. It looks like sometimes (but not always) the etag returned by Calling |
To be clear, this isn't an API bug. The client should silently reload the subject as needed. |
OOI - the created 201 and any update 200 response should include the updated etag for the resource. I assume calling |
I'm not sure why the etag is wrong sometimes when it's usually fine most of the time. |
i wonder if the resource is being updated in the API and thus changing the etag value? I can't think what would be updating the subject behind the scenes API side.... but something might touch that resource. It would be a waste to add a reload on each save event as it's a double round trip to the API and most likely not needed 90% of the time so would slow client calls down and possibly double the API load for these actions. Could the client rescue this specific error and retry with a |
I wouldn't want that to happen automatically in the client because it could be dangerous to overwrite whatever changes there could have been, but that's what I'll do to work around the issue here. I'm not really sure what the solution is -- maybe an explicit option on |
For reference here's how I'm working around it: for retry in (True, False):
try:
... make changes to subject ...
subject.save()
except PanoptesAPIException:
if retry:
# Reload the subject to refresh the etag
# This works around what seems to be a bug in the Panoptes client
# https://github.com/zooniverse/panoptes-python-client/issues/220
subject.reload()
else:
raise |
Ideally we find the source of this bug eventually but it looks like your workaround will help folks encountering this issue. |
One problem with this approach is that the client DOES retry the failing requests with a backoff interval, but they always fail until you call |
In fact with the backoff it would be fewer requests to just call reload first every time. |
This simple metadata correction code is not working...
Traceback (most recent call last):
File "C:/py_scripts/Scripts_WoW/subject_update_metadata_from_file_simplified.py", line 10, in
subject.save()
File "C:\Users\User1\AppData\Local\Programs\Python\Python37-32\lib\site-packages\panoptes_client\subject.py", line 143, in save
log_args=False,
File "C:\Users\User1\AppData\Local\Programs\Python\Python37-32\lib\site-packages\redo_init_.py", line 185, in retry
return action(*args, **kwargs)
File "C:\Users\User1\AppData\Local\Programs\Python\Python37-32\lib\site-packages\panoptes_client\panoptes.py", line 815, in save
etag=self.etag
File "C:\Users\User1\AppData\Local\Programs\Python\Python37-32\lib\site-packages\panoptes_client\panoptes.py", line 362, in put
retry=retry,
File "C:\Users\User1\AppData\Local\Programs\Python\Python37-32\lib\site-packages\panoptes_client\panoptes.py", line 281, in json_request
json_response['errors']
panoptes_client.panoptes.PanoptesAPIException: JsonApiController::PreconditionFailed
This workaround does work: Update This ran without errors but did not add a field "Volume" to the subject metadata. It seems I can no longer update subject metadata on existing subjects???
The text was updated successfully, but these errors were encountered: