title: Updating a model by method: SQLAlchemy
body: <p>I have method on a model Thing:</p>
  
  <pre><code>def method(self, session):
          if self.column_value is None:
              self.column_value = some expensive calculation
              session.add(self)
              session.commit()
              return self.column_value                        
          else:
              return self.column_value
  </code></pre>
  
  <p>So, I can run thing_instance.method and return column_value, calculating if needed. This is how I did it elsewhere, and I'm trying to adapt to doing this w/python.</p>
  
  <p>This is not working as I'd like, I'm getting errors galore....what is a better way?</p>
  
  <p>EDIT:</p>
  
  <p>That method is it in a nutshell. I have thing_instance and call thing_instance.method(). The error I'm getting is:</p>
  
  <pre><code>sqlalchemy.exc.InterfaceError: (InterfaceError) Error binding parameter 0 - probably unsupported type
  </code></pre>
  
  <p>Which might be more useful.</p>
  
  <p>I would put more specific code as requested, but that would distract from my question. The issue here is: How exactly do I write a method on sqlalchemy model that calculates and updates the instance column value if the column value is not set? In a pythoinic/sqlalchemic way? What I tried in variations did not work, so I put it aside, asked this question</p>
  
  <p>EDIT2:</p>
  
  <p>It was a column type error.....calculated value was a list, and I need to convert or use PickleType as column. Any pointers still appreciated.</p>