On Dec 20, 2010, at 3:42 AM, Torsten Landschoff wrote:

> Hi all.
> 
> I just stumbled across an after_attach event handler in my code. That
> handler used to replace a None reference with a persistent instance that
> was already loaded.
> 
> After a few changes, it ended up doing a query to load that instance. It
> seems this messes up the session state, which caused a query to change
> from
> 
> INSERT INTO group_items (group_id, item_id, item_order) VALUES (?, ?, ?)
> (242, 244, 0)
> 
> into the less usefull
> 
> INSERT INTO group_items (group_id, item_id, item_order) VALUES (?, ?, ?)
> (None, None, None)
> 
> Both the group and the item where created correctly so I ended up with a
> database which has all the data, just missing their relationships ;-)
> 
> 
> I reverted to running the query when first connecting to the database.
> What I would like to know: Is it officially impossible to run queries
> from session events? What session functionality is usable from within
> session events? (I know that session.{dirty, new, deleted} works fine).

I can't think of anything that would go wrong from running a Query inside of 
the events - the flush process itself runs queries.   Also in the 
before_flush() event you can also change the state of the session to any degree.

In this case, we have another verb besides "Query", which is "replace", as in 
"replace a None reference".   That sounds like the thing you're doing that 
changes state, likely in an unexpected way based on your description.   Would 
need to understand what you mean by "replace" here and under what codepath 
that's occurring.   Under a normal "attach" event via a userland "add()" it 
should be OK.



> 
> Thanks and happy holidays,
> 
> Torsten
> 
> -- 
> DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH
> Torsten Landschoff
> 
> Office Dresden
> Tel: +49-(0)351-4519587
> Fax: +49-(0)351-4519561
> 
> mailto:torsten.landsch...@dynamore.de
> http://www.dynamore.de
> 
> Registration court: Mannheim, HRB: 109659, based in Karlsruhe,
> Managing director:  Prof. Dr. K. Schweizerhof, Dipl.-Math. U. Franz
> 
> -- 
> 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.
> 

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