librelist archives

« back to archive

Using Versioned Objects recipe with Flask-sqlalchemy

Using Versioned Objects recipe with Flask-sqlalchemy

2013-07-05 @ 22:25
I've been trying to get the Sqlalchemy (0.8.1) Versioned Objects recipe (
 to work with the flask-sqlalchemy (0.16) extension with no luck.

I've modified my VersionedMeta class with Armin's comments and it now looks
like this:

db = SQLAlchemy()
MetaBase = type(db.Model)

class VersionedMeta(MetaBase):
    def __init__(cls, classname, bases, dict_):
        MetaBase.__init__(cls, classname, bases, dict_)

            mapper = class_mapper(cls)
        except UnmappedClassError:

The problem I seem to be facing is that the VersionedListener
SessionExtension class never seems to call before_flush.  Which is weird
since if I add it [before_flush] to the
- _SignallingSessionExtension class, it works successfully.  My impression
was that any extensions added in the call:

db = SQLAlchemy(app, session_extensions=[VersionedListener()])

Would be called before the _SignallingSessionExtension extension.  So I'm
not quite sure why it doesn't work from my class.

Ironically this and VersionedListener class is the one used
in the Flask-sqlalchemy session_extensions comment example.  So any help in
this matter would be greatly appreciated.