title: updating table attributes using kwargs Flask-SQLAlchemy
body: <p>I am using Flask-SQLAlchemy. I have a table with several attributes. I have a dictionary where <code>key='attribute-name'</code> and <code>value=the_new_value</code>.</p>
  
  <p>I want to update an existing row/entry using the dictionary. Is there a way to update an entry using <code>**kwargs</code> rather than updating them one-at-a-time manually?</p>
  
  <p>I found two references to a <code>set_attribute</code> method in SQLAlchemy: <a href="https://stackoverflow.com/questions/29830229/force-object-to-be-dirty-in-sqlalchemy">here</a> and <a href="https://stackoverflow.com/questions/31212392/how-do-i-update-related-object-on-update-in-sqlalchemy">here</a>, however both address more specific problems than the one I am asking.</p>
  
  <p>I have tried <code>set_attribute</code> and it doesn't work for me. I don't get any error messages, but the database attributes do not change. I am wondering:</p>
  
  <p>1) what is proper way to access/import <code>set_attribute</code> in Flask-SQLAlchemy?</p>
  
  <p>2) can keys be stored as strings for **kwargs in <code>set_attribute</code>?</p>
  
  <p>3) if neither 1) or 2) is my problem, what is?</p>
  
  <p>As for code, this is kind of what it looks like, first the model:</p>
  
  <pre><code>class Files(UserMixin, db.Model):
      id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
      filename_main = db.Column(db.String(264))
      filename_side1 = db.Column(db.String(264))
      filename_side2 = db.Column(db.String(264))
  
      def update(self, **kwargs):
         for key, value in kwargs.items():
                 set_attribute(self, key, value)
  </code></pre>
  
  <p>And in the view, I'd like to do something like this:</p>
  
  <pre><code>files = Files.query.filter_by(id=id).first()
  filenames = {'filename_main': 'main.ext', 
               'filename_side1': 'side1.ext', 
               'filename_side2': 'side2.ext'}
  files.update(**filenames)
  </code></pre>