[sqlalchemy] Re: session.query().get() is unsupported during flush for getting an object that was just added?

2012-02-06 Thread Kent
On Feb 1, 3:17 pm, Kent jkentbo...@gmail.com wrote:
  If the value is based on what's already been INSERTed for previous rows, 
  I'd emit a SQL statement to get at the value.If it's based on some kind 
  of natural consideration that isn't dependent on the outcome of an INSERT 
  statement, then you can do the looping above within the before_flush() 
  event and assign everything at once.Basically you need to batch the 
  same way the UOW itself does.

 is IdentitySet an OrderedSet?  if I loop through session.new, for
 example, am I guaranteed to hit these in the same order they were
 added to the session?

Is there a way to work out the order in which session.new items were
added... I take it session.new is not ordered.
Did you mention you were in the works of an instance level event for
'before_flush()', similar to 'before_insert/before_update'?

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



Re: [sqlalchemy] Re: session.query().get() is unsupported during flush for getting an object that was just added?

2012-02-06 Thread Michael Bayer

On Feb 6, 2012, at 4:05 PM, Kent wrote:

 On Feb 1, 3:17 pm, Kent jkentbo...@gmail.com wrote:
 If the value is based on what's already been INSERTed for previous rows, 
 I'd emit a SQL statement to get at the value.If it's based on some kind 
 of natural consideration that isn't dependent on the outcome of an INSERT 
 statement, then you can do the looping above within the before_flush() 
 event and assign everything at once.Basically you need to batch the 
 same way the UOW itself does.
 
 is IdentitySet an OrderedSet?  if I loop through session.new, for
 example, am I guaranteed to hit these in the same order they were
 added to the session?
 
 Is there a way to work out the order in which session.new items were
 added... I take it session.new is not ordered.

InstanceState has an attribute insert_order that's assigned as objects are 
added, so the sort at flush time is based on that attribute.   It is unique 
across all of session.new.

 Did you mention you were in the works of an instance level event for
 'before_flush()', similar to 'before_insert/before_update'?

there's room to support a series of extensions to the before_flush() listener 
such that it would provide filtered collections or individual instances to the 
listener callable.Some notion of this was always in mind, though actually 
implementing it is way down on my list of priorities.It would be 
implemented within a _listen method on SessionEvents.   _listen() is called by 
the event system when a user-defined listener function is first established 
against an event.In this case the given listener function would be wrapped 
inside a filtering callable that calls it as many times as needed passing in 
the appropriate objects.For examples of listeners being wrapped on listen, 
see AttributeEvents._listen, InstanceEvents._listen, MapperEvents._listen.


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



[sqlalchemy] Re: session.query().get() is unsupported during flush for getting an object that was just added?

2012-02-01 Thread Kent
 If the value is based on what's already been INSERTed for previous rows, I'd 
 emit a SQL statement to get at the value.If it's based on some kind of 
 natural consideration that isn't dependent on the outcome of an INSERT 
 statement, then you can do the looping above within the before_flush() event 
 and assign everything at once.Basically you need to batch the same way 
 the UOW itself does.

is IdentitySet an OrderedSet?  if I loop through session.new, for
example, am I guaranteed to hit these in the same order they were
added to the session?

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