title: Using an older deployment after update
body: <p>I'm trying to make a wedding website using this person's blog/github: <a href="https://blog.rampatra.com/wedding-website" rel="nofollow noreferrer">https://blog.rampatra.com/wedding-website</a>. I had this to where when someone filled out the form on my website, I received an email and my google spreadsheet updated. Then we needed a shorter invite code, so I changed the logic. Now, when I enter the new code, I get an error message saying the new code is invalid and the old code still works even though anything other than the new code should be throwing an error.</p>
  <p>I have an HTML form on my index.html exactly like the original.</p>
  <p>I also have a section in my scripts.js that was identical to the example:</p>
  <pre><code>/********************** RSVP **********************/
  $('#rsvp-form').on('submit', function (e) {
  e.preventDefault();
  var data = $(this).serialize();
  
  $('#alert-wrapper').html(alert_markup('info', '&lt;strong&gt;Just a sec!&lt;/strong&gt; We are 
  saving your details.'));
  
  if (MD5($('#invite_code').val()) !== 'b0e53b10c1f55ede516b240036b88f40'
      &amp;&amp; MD5($('#invite_code').val()) !== '2ac7f43695eb0479d5846bb38eec59cc') {
      $('#alert-wrapper').html(alert_markup('danger', '&lt;strong&gt;Sorry!&lt;/strong&gt; Your 
  invite code is incorrect.'));
  } else {
  
  $.post
  ('https://script.google.com/macros/s/&lt;my deployment id&gt;-/exec', data)
          .done(function (data) {
              console.log(data);
              if (data.result === &quot;error&quot;) {
                  $('#alert-wrapper').html(alert_markup('danger', data.message));
              } else {
                  $('#alert-wrapper').html('');
                  $('#rsvp-modal').modal('show');
              }
          })
          .fail(function (data) {
              console.log(data);
              $('#alert-wrapper').html(alert_markup('danger', '&lt;strong&gt;Sorry!&lt;/strong&gt; 
  There is some issue with the server. '));
          });
  }
  });
  </code></pre>
  <p>For my google sheet, I used the example script and initially only changed the email address</p>
  <pre><code>var TO_ADDRESS = &quot;youremailaddress@gmail.com&quot;; // email to send the form data to
  
  /**
  * This method is the entry point.
  */
  function doPost(e) {
  
  try {
  Logger.log(e); // the Google Script version of console.log see: Class Logger
  
  var mailData = e.parameters; // just create a slightly nicer variable name for the 
  data
  
  if (mailData.invite_code != &quot;271117&quot;) { // validate invite code before saving data
    Logger.log(&quot;Incorrect Invite Code&quot;);
    return ContentService
        .createTextOutput(JSON.stringify({&quot;result&quot;:&quot;error&quot;, &quot;message&quot;: &quot;Sorry, your 
  invite code (&quot; + mailData.invite_code + &quot;) is incorrect.&quot;}))
        .setMimeType(ContentService.MimeType.JSON);
  }
  
  record_data(e);
  
  MailApp.sendEmail({
    to: TO_ADDRESS,
    subject: &quot;A new guest RSVP'd for your wedding&quot;,
    replyTo: String(mailData.email), // This is optional and reliant on your form 
   actually collecting a field named `email`
    htmlBody: formatMailBody(mailData)
  });
  
  return ContentService    // return json success results
        .createTextOutput(JSON.stringify({&quot;result&quot;:&quot;success&quot;,&quot;data&quot;: 
  JSON.stringify(e.parameters) }))
        .setMimeType(ContentService.MimeType.JSON);
  } catch(error) { // if error return this
  Logger.log(error);
  return ContentService
        .createTextOutput(JSON.stringify({&quot;result&quot;:&quot;error&quot;, &quot;message&quot;: &quot;Sorry, there is 
  an issue with the server.&quot;}))
        .setMimeType(ContentService.MimeType.JSON);
  }
  }
  
  
  /**
  * This method inserts the data received from the html form submission
  * into the sheet. e is the data received from the POST
  */
  function record_data(e) {
  Logger.log(JSON.stringify(e)); // log the POST data in case we need to debug it
  try {
  var doc     = SpreadsheetApp.getActiveSpreadsheet();
  var sheet   = doc.getSheetByName('responses'); // select the responses sheet
  var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
  var nextRow = sheet.getLastRow()+1; // get next row
  var row     = [ new Date().toUTCString() ]; // first element in the row should always 
  be a timestamp
  // loop through the header columns
  for (var i = 1; i &lt; headers.length; i++) { // start at 1 to avoid Timestamp column
    if(headers[i].length &gt; 0) {
      row.push(e.parameter[headers[i]]); // add data to row
    }
  }
  // more efficient to set values as [][] array than individually
  sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
  }
  catch(error) {
  Logger.log(error);
  Logger.log(e);
  throw error;
  }
  finally {
  return;
  }
  }
  </code></pre>
  <p>After I got the example working, I changed my Google AppScript to <code>if(mailData.invite_code !=&quot;271117&quot;)</code> to a new code and then hit deploy -&gt; new deployment. I copied the new deployment ID and hit deploy. The new version seemed to deploy.</p>
  <p>In scripts.js I changed:</p>
  <pre><code>  (MD5($('#invite_code').val()) !== 'b0e53b10c1f55ede516b240036b88f40'
  </code></pre>
  <p>to the hash of the new code and</p>
  <pre><code>  $.post
    ('https://script.google.com/macros/s/&lt;my deployment id&gt;-/exec', data)
  </code></pre>
  <p>to the new deployment id</p>
  <p>I saved my code with the new deployment id, committed, and ran terraform apply and updated the S3 bucket. I went back to my website and completed the RSVP form again.</p>
  <p>The website changes URL to one that has the json response and says &quot;Sorry, your invite code (mycode) is incorrect&quot;. That code matches the code in my script exactly. If I fill out a new RSVP with the code from the example, it works as if I didn't change anything. When I check the 'executions' table in Apps Scripts, the deployment version kicked off is the older one.</p>
  <p>Do I need to archive the old deployment? Is there a delay, and if there is a delay why isn't my scripts.js failing?</p>