librelist archives

« back to archive

Using Versioned Objects recipe with Flask-sqlalchemy

Using Versioned Objects recipe with Flask-sqlalchemy

From:
A B
Date:
2013-07-05 @ 22:25
I've been trying to get the Sqlalchemy (0.8.1) Versioned Objects recipe (
http://docs.sqlalchemy.org/en/rel_0_8/orm/examples.html#versioned-objects)
 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_)

        try:
            mapper = class_mapper(cls)
            _history_mapper(mapper)
        except UnmappedClassError:
            pass

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 flask_sqlalchemy.py
- _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 history_meta.py 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.