Hello,

According to docs, I can use class level methods and variables with the ScopedSession: Since theSession() <http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.session.Session>constructor now returns the sameSession <http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.session.Session>object every time within the current thread, the object returned byscoped_session() <http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.scoped_session>also implements most of theSession <http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.session.Session>methods and properties at the "class" level, such that you don't even need to instantiateSession() <http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.session.Session>

However, when I tried this on 0.6.5 and 0.6.6 - it did not work. Looks like not all expected variables are exposed, or they were renamed and ScopedSession object was not behaving as would one expect from Session object.
Basically, here is sample stack trace:
File "C:\Python26\lib\site-packages\sqlalchemy-0.6.6-py2.6.egg\sqlalchemy\orm\query.py", line 1646, in one
ret = list(self)
File "C:\Python26\lib\site-packages\sqlalchemy-0.6.6-py2.6.egg\sqlalchemy\orm\query.py", line 1688, in __iter__
self.session._autoflush()
AttributeError: 'ScopedSession' object has no attribute '_autoflush'

So, I decided to add all missing attributes by monkey patching the ScopedSession class for now.

 Essentially this did the trick:

def patch_sqlalchemy():
    from sqlalchemy.orm.scoping import ScopedSession, makeprop

    for prop in ('_autoflush', 'hash_key', '_finalize_loaded'):
        setattr(ScopedSession, prop, makeprop(prop))

patch_sqlalchemy()


I don't know if it right solution, or class-level attributes are no longer supported, etc.

Please advice.

Thank you,
Serge.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to