To expand and clarify Simon's answer into bulletpoints : Expired Object * The database Session the object belongs to has been closed ( or committed unless you tweaked the config ) * SqlAlchemy considers it 'expired' because it is not reasonable to expect the object to reflect the current state of the database * the object must be reloaded from the db or 'merged' into a new session.
Dirty Object * There have been changes to attributes on a "Clean" object loaded from the database * Changing an attribute , or adding an object, doesn't automatically write to the database. * You must explicitly call `flush()` to write the database, or `commit()` to both write to the database and commit the transaction. Overall * SqlAlchemy is your friend and looks out for you, avoiding common mistakes: * It automatically reloads most "Expired Objects" from the database (and raises an error at other times) so you have the most correct data in the ORM * It makes you explicitly write to the database when you have new objects or changes to commit. While it could be possible to extend SqlAlchemy to automatically 'write' to the database when you change an attribute, that would cause a lot of SQL overhead and probably screw up constraint checks. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
