On Wed, Jan 16, 2019 at 4:18 PM Gmoney <grgg...@gmail.com> wrote:
>
> I was having a heck of confusing time debugging some code where I was trying 
> to determine what attrs on an ORM changed prior to committing it.  Every time 
> in my debugger I'd be getting different results (w/r to History).  I finally 
> realized that autoflush was enabled, and now that I disabled it, things seem 
> much more sane.  The strange part though, is that the update/flush would 
> occur randomly while I was just iterating through some mapper attributes 
> checking History.  No queries, no nothing... but at one point... whoosh... it 
> must have flushed.

autoflush only happens when the ORM runs a Query, call commit(), or
when you start a SAVEPOINT transaction.    You will see autoflush
happen when you do things like access attributes, because lazyloading
of attributes uses Query in order to load the data.      So it is
definitely happening "synchronously", that is, there is certainly
nothing like a background thread running, but it at first can seem
surprising what operations require autoflush to occur.

it's entirely reasonable to turn off autoflush if you're only doing
simple operations, though often it's a good idea to limit when you
disable autoflush only to blocks where necessary using "with
session.no_autoflush".

I strongly recommend doing a little bit of work in the debugger or
console with echo=True turned on so that you can see SQL being
emitted.


>
> I'm basing the 'has flushed' inference on the fact that my test update is 
> updating a foreign key relationship.  I update the relationship object (not 
> the ID) on the primary object.  At that point, the FK id is still the old id 
> from prior to the change.  Only when I Flush, does the id get updated 
> automatically.  Well I watch that ID in a debug watch, and boom... it just 
> randomly updates at some point when I'm walking through unrelated fields 
> checking for history (not issuing any querys or session activity, as far as I 
> can tell).
>
> Just looking for a sanity check if this behavior seems to make sense?  I 
> would have thought the auto flushing would happen inline with a query... like 
> you step over that query or operation, and the autoflush occurs 
> synchronously.  This is not what I'm seeing.
>
> --
> 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.

-- 
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.

Reply via email to