I'm using "marshmallow-sqlalchemy" (mmsqla), a small wrapper around the "marshmallow" marshalling/serializing library. I'm using my defined mmsqla schemas to serialize a parent record with multi-level nested relationships and sending that to a webpage, which changes one of the relationship references, setting say the "favouriteFruit" of "Child1" from Apple to Orange, and posts back to my app. The mmsqla deserialization process queries for the "Child1" instance, loads the Orange instance and assigns it to favouriteFruit (which was Apple), and puts Child1 in the parent's collection. I can hack into mmsqla as it sets favouriteFruit to Orange and use sqlalchemy.orm.attributes.get_history() to indeed see that Orange is "added" and Apple is "deleted".
But by the time I get my parent instance back normally from mmsqla, the history is no longer available. This would seem to because history doesn't survive a session flush(). I think that the default autoflush behaviour on a session is getting triggered by the queries for the remaining deserialization. As far as I can tell, by the time mmsqla returns the parent instance to me, I have no way of knowing that some of the related stuff has been changed, and for certain types of changes I need to know this so I can run some additional code. The history is already gone by the time the general schema post_load hooks get fired off, and there doesn't seem to be any supported way to provide a function to execute for a specific Nested scheme field. I was thinking I might try setting session.autoflush to False just before calling the deserializer, and set it back when it returns, so that nothing is flushed. I'll be checking with the mmsqla project as well, but I was curious if anyone had any experience with anything similar to this, and whether having autoflush off while a complex instance is being put back together by the deserializer sounds like a bad idea in principle (or would even work)? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.