On Apr 11, 2010, at 4:28 PM, Peteris Krumins wrote:

> Hey everyone,
> 
> Is it the expected behavior that after querying an object with
> `session.query(...).autoflush(False)...` and modifying some of its
> fields still makes it issue UPDATE when a relation of the object is
> referenced?
> 
> Let me illustrate what I mean precisely. First I query the Page class:
> 
>    page =
> session.query(Page).autoflush(False).filter_by(page_id=...).first()
> 
> Next, I assign a new title for the page:
> 
>    page.title = "new title"
> 
> Now the page also has the `path` property that is a relation on Paths
> table. As soon as I do:
> 
>    print page.path
> 
> I see that SQLAlchemy issues an UPDATE statement for the page.title,
> even though the page was said to be autoflush=False.
> 
> I am wondering if this is the expected behavior? While the page should
> not autoflush, the relation still uses the session with
> autoflush=True. Somehow the relation's autoflush overtakes the Page
> query's autoflush and an UPDATE is issed...

The behavior of page.path has no connection to the query(Page) previously 
emitted, and the autoflush() option on Query only refers to the flush() which 
would occur when that Query emits SQL.   The Page object could just as well 
have already been present in the session when your query happened to return it 
- in which case it would be ambiguous which "autoflush" behavior it should be 
following.   You can set autoflush to False on the Session directly and its 
advised that you use a context manager to make it convenient, as in 
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DisableAutoflush .



-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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