title: PickleType with Mutable Tracking in SqlAlchemy
body: <p>I have a project where I would like to store a large structure (nested objects) in a relational db (Postgres). It's part of a larger structure and I don't really care about the serialization format - I'm happy for it to be a blob in a column - I'd just like to be able to persist and restore it fairly quickly.</p>
  
  <p>For my purposes the SQLAlchemy PickleType mostly does the job. The issue I have is that I'd like the dirty checks to work (something that the Mutable Types are used for). I'd like them to work not only if I change info in the paths but also in the bounds (which sit another level down).</p>
  
  <pre><code>class Group(Base):
      __tablename__ = 'group'
  
      id = Column(Integer, primary_key=True)
      name = Column(String, nullable=False)
      paths = Column(types.PickleType)
  
  class Path(object):
      def __init__(self, style, bounds):
          self.style = style
          self.bounds = bounds
  
  class Bound(object):
      def __init__(self, l, t, r, b):
          self.l = l
          self.t = t
          self.r = r
          self.b = b
  
  # this is all fine
  g = Group(name='g1', paths=[Path('blah', Bound(1,1,2,3)),
                              Path('other_style', Bound(1,1,2,3)),])
  session.add(g)
  session.commit()
  
  # so is this
  g.name = 'g2'
  assert g in session.dirty
  session.commit()
  
  # but this won't work without some sort of tracking on the deeper objects
  g.paths[0].style = 'something else'
  assert g in session.dirty # nope
  </code></pre>
  
  <p>I've played around with the Mutable types trying to get it working but haven't had any luck. Elsewhere I do use the mutable types for a json column which is fine - in a way that seems simpler though because with these classes you need to track changes to objects within the objects too.</p>
  
  <p>Any thoughts appreciated.</p>