title: Upsert with optimistic locking with DynamoDB and Boto3
body: <p>I am trying to implement an upsert of an item into DynamoDB with optimistic locking. I have the update portion working with a <code>ConditionExpression</code> to check the version. But this fails the save portion as the <code>ConditionExpression</code> is false for saving. Is it possible to write the <code>ConditionExpression</code> so that it will handle both situations?</p>
  
  <p>My code:</p>
  
  <pre><code>result = copy.copy(user)
  table = get_db_table()
  
  current_version = result.get_version()
  result.update_version()
  
  try:
      table.put_item(
          Item=result.to_table_item(),
          ConditionExpression=Attr(result.get_version_key()).eq(current_version)
      )
  except ClientError as error:
      logger.error(
          "Saving to db failed with '%s'",
          str(error))
      # Restore version
      result.set_version(current_version)
      raise Exception(ErrorCode.DB_SAVE) from error
  return result
  </code></pre>