[Archivesspace_Users_Group] Error updating resource records through API
Hi all, I've been attempting to update existing resource records through the API, the records already exist and I'm trying to upload modified versions of the JSON but I'm getting an error in response. 'error': 'The record you tried to update has been modified since you fetched it.' At first I thought this meant either user_mtime, system_mtime, or create_time were preventing uploading an older version of the file but the error persists after replacing all time stamps with the current date and time. Does anyone know what this error means? Using ASnake: resources = glob.glob('./resources/modified/' + '*.json') for file in resources: resources_id = file.rstrip('.json') resources_id = re.findall('\d+', resources_id) resource = json.load(open(file)) response = client.post('repositories/2/resources/' + resources_id[0], json=resource).json() if response.get('error') != None: print("*") print(resources_id[0]) print(response['error']) print(file) print("*") -Alan ___ Archivesspace_Users_Group mailing list Archivesspace_Users_Group@lyralists.lyrasis.org http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
Re: [Archivesspace_Users_Group] Error updating resource records through API
Are you modifying the lock version? Donald R. Mennerich, digital archivist New York University Libraries don.menner...@nyu.edu (212) 992-6264 On Fri, Apr 17, 2020 at 10:26 AM Huebschen, Alan M wrote: > Hi all, > > > > I’ve been attempting to update existing resource records through the API, > the records already exist and I’m trying to upload modified versions of the > JSON but I’m getting an error in response. > > > > *'error': 'The record you tried to update has been modified since you > fetched it.'* > > > > At first I thought this meant either user_mtime, system_mtime, or > create_time were preventing uploading an older version of the file but the > error persists after replacing all time stamps with the current date and > time. > > > > Does anyone know what this error means? > > > > Using ASnake: > > > > resources = glob.glob('./resources/modified/' + '*.json') > > > > for file in resources: > > resources_id = file.rstrip('.json') > > resources_id = re.findall('\d+', resources_id) > > resource = json.load(open(file)) > > response = client.post('repositories/2/resources/' + > resources_id[0], json=resource).json() > > > > if response.get('error') != None: > > print("*") > > print(resources_id[0]) > > print(response['error']) > > print(file) > > print("*") > > > > -Alan > ___ > Archivesspace_Users_Group mailing list > Archivesspace_Users_Group@lyralists.lyrasis.org > > https://urldefense.proofpoint.com/v2/url?u=http-3A__lyralists.lyrasis.org_mailman_listinfo_archivesspace-5Fusers-5Fgroup&d=DwICAg&c=slrrB7dE8n7gBJbeO0g-IQ&r=_DsNVvE0MidyDzdUOYchWsIErjGtgLba7OOoi6MzJhM&m=mAyTL3XUpdR3rCWgQczVnW4usjHSykz_ZyAX8DSLHbA&s=TCqiDc22Sk_MwNFxjNgl9hkMr83FqBWe-zrDgS14iHM&e= > ___ Archivesspace_Users_Group mailing list Archivesspace_Users_Group@lyralists.lyrasis.org http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
Re: [Archivesspace_Users_Group] Error updating resource records through API
So, ArchivesSpace keeps track of whether it’s safe to modify an object via a field called “lock_version”. Any change to an object will increment this value, and this is probably what’s catching you up – something is altering the value between when you download the resource and when you update it. There’s two things you can do. - you can change the script you you fetch the JSON right before modifying and uploading it. - you can delete lock_version from the object The second carries risks, because if it’s failing because something else has modified the object in question, those changes can be lost. -- Dave Mayo (he/him) Senior Digital Library Software Engineer Harvard University > HUIT > LTS From: on behalf of "Huebschen, Alan M" Reply-To: Archivesspace Users Group Date: Friday, April 17, 2020 at 10:26 AM To: Archivesspace Users Group Subject: [Archivesspace_Users_Group] Error updating resource records through API Hi all, I’ve been attempting to update existing resource records through the API, the records already exist and I’m trying to upload modified versions of the JSON but I’m getting an error in response. 'error': 'The record you tried to update has been modified since you fetched it.' At first I thought this meant either user_mtime, system_mtime, or create_time were preventing uploading an older version of the file but the error persists after replacing all time stamps with the current date and time. Does anyone know what this error means? Using ASnake: resources = glob.glob('./resources/modified/' + '*.json') for file in resources: resources_id = file.rstrip('.json') resources_id = re.findall('\d+', resources_id) resource = json.load(open(file)) response = client.post('repositories/2/resources/' + resources_id[0], json=resource).json() if response.get('error') != None: print("*") print(resources_id[0]) print(response['error']) print(file) print("*") -Alan ___ Archivesspace_Users_Group mailing list Archivesspace_Users_Group@lyralists.lyrasis.org http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
Re: [Archivesspace_Users_Group] Error updating resource records through API
Huebschen, Alan M wrote on 2020-04-17 14:26:24: > I've been attempting to update existing resource records through the API, the > records already exist and I'm trying to upload modified versions of the JSON > but I'm getting an error in response. > > 'error': 'The record you tried to update has been modified since you fetched > it.' To update a record, you first need to fetch it to get its lock_version. The API will only allow updates to a resource with a lock_version greater than the one stored in the database, so you'll need to post your data including lock_version+1. Hope that helps, p ___ Archivesspace_Users_Group mailing list Archivesspace_Users_Group@lyralists.lyrasis.org http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
Re: [Archivesspace_Users_Group] Error updating resource records through API
You can just send back the lock_version you got with the get. No need to bump it - that happens on a successful update. The response to the update will include the new lock_version, like this: { "status": "Updated", "id": 2, "lock_version": 23, "stale": NULL, "uri": "/repositories/2", "warnings": [] } This is implemented via a sequel plugin: https://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel/Plugins/OptimisticLocking.html > On Apr 18, 2020, at 12:53 AM, Peter Heiner wrote: > > Huebschen, Alan M wrote on 2020-04-17 14:26:24: >> I've been attempting to update existing resource records through the API, >> the records already exist and I'm trying to upload modified versions of the >> JSON but I'm getting an error in response. >> >> 'error': 'The record you tried to update has been modified since you fetched >> it.' > > To update a record, you first need to fetch it to get its lock_version. > The API will only allow updates to a resource with a lock_version > greater than the one stored in the database, so you'll need to post your > data including lock_version+1. > > Hope that helps, > p > ___ > Archivesspace_Users_Group mailing list > Archivesspace_Users_Group@lyralists.lyrasis.org > http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group > > !DSPAM:5e99c2e335501411550710! ___ Archivesspace_Users_Group mailing list Archivesspace_Users_Group@lyralists.lyrasis.org http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group