[sqlalchemy] IntegrityError on Association Proxy

2014-11-26 Thread Erkan Özgür Yılmaz
Hi, I've encountered a situation where I don't know if this is a bug or it is the correct behavior. It is about association_proxy. Please see the User.__init__ and Department.__init__ methods. from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import

Re: [sqlalchemy] IntegrityError on Association Proxy

2014-11-26 Thread Michael Bayer
take a look at the stack trace (or send it along). Do you see autoflush in it? If so, you should use “with session.no_autoflush” around the area where you are likely triggering a lazy load of an attribute or collection.

Re: [sqlalchemy] IntegrityError on Association Proxy

2014-11-26 Thread Erkan Özgür Yılmaz
Yes it recommends using ``no_autoflush`` and: with DBSession.no_autoflush: dep1.users.append(user2) fixes it. So is this the correct way appending to the collection, and should I wrap all code that is manipulating ``Department.users`` with a ``no_autoflush``? Erkan Ozgur Yilmaz On Thu,

Re: [sqlalchemy] IntegrityError on Association Proxy

2014-11-26 Thread Michael Bayer
well depending on when you last loaded that collection and/or committed it might already be loaded. but if it isn’t loaded, autoflush is pretty simplistic, it flushes before the collection is loaded. other things you can look into for tuning this are to make it less likely for the object to