<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">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.<br>
<br>
There’s two things you can do.  <br>
<br>
- you can change the script you you fetch the JSON right before modifying and uploading it.    <o:p></o:p></p>
<div>
<p class="MsoNormal">- you can delete lock_version from the object<br>
<br>
The second carries risks, because if it’s failing because something else has modified the object in question, those changes can be lost.<o:p></o:p></p>
<p class="MsoNormal"><br>
--<o:p></o:p></p>
<p class="MsoNormal">Dave Mayo (he/him)<o:p></o:p></p>
</div>
<p class="MsoNormal">Senior Digital Library Software Engineer<br>
Harvard University > HUIT > LTS<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black"><archivesspace_users_group-bounces@lyralists.lyrasis.org> on behalf of "Huebschen, Alan M" <ahueb2@uis.edu><br>
<b>Reply-To: </b>Archivesspace Users Group <Archivesspace_Users_Group@lyralists.lyrasis.org><br>
<b>Date: </b>Friday, April 17, 2020 at 10:26 AM<br>
<b>To: </b>Archivesspace Users Group <Archivesspace_Users_Group@lyralists.lyrasis.org><br>
<b>Subject: </b>[Archivesspace_Users_Group] Error updating resource records through API<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">Hi all,<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">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.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><b>'error': 'The record you tried to update has been modified since you fetched it.'</b><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">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.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Does anyone know what this error means?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Using ASnake:<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">resources = glob.glob('./resources/modified/' + '*.json')<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">    for file in resources:<o:p></o:p></p>
<p class="MsoNormal">        resources_id = file.rstrip('.json')<o:p></o:p></p>
<p class="MsoNormal">        resources_id = re.findall('\d+', resources_id)<o:p></o:p></p>
<p class="MsoNormal">        resource = json.load(open(file))<o:p></o:p></p>
<p class="MsoNormal">        response = client.post('repositories/2/resources/' + resources_id[0], json=resource).json()<o:p></o:p></p>
<p class="MsoNormal">    <o:p></o:p></p>
<p class="MsoNormal">        if response.get('error') != None:<o:p></o:p></p>
<p class="MsoNormal">            print("*")<o:p></o:p></p>
<p class="MsoNormal">            print(resources_id[0])<o:p></o:p></p>
<p class="MsoNormal">            print(response['error'])<o:p></o:p></p>
<p class="MsoNormal">            print(file)<o:p></o:p></p>
<p class="MsoNormal">            print("*")<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">-Alan<o:p></o:p></p>
</div>
</body>
</html>