On May 6, 2010, at 2:29 PM, Kent wrote: > > > ord=DBSession.query(Order).get(u'SALE65424') > > ord.customerid #this returns the current value, '7' > > ord.customerid = u'8' #update this value > > ord.customer # lazy load > =========================================================== > > Even after the join criterion was changed (and even flushed to the > database), the lazy load fetched the 'wrong' customer, using the old > value of the customerid. > > Is the behavior by design? > > The possible rationale is "this makes relationship loading consistent > regardless of autoflush being enabled and also regardless of eager vs. > lazy loading". But, at the end of the day, the example above just > seems wrong. > > A longer term enhancement to sqla might be to automatically expire any > relation whose join columns include a column that gets updated in a > session? Is that a manageable effort?
The short answer is "no". This is the oldest caveat to SQLAlchemy's ORM still remaining, and is described here: http://www.sqlalchemy.org/trac/wiki/FAQ#Isetthefoo_idattributeonmyinstanceto7butthefooattributeisstillNone-shouldntithaveloadedFoowithid7 Basically the implications here are significant, and a lot of thought would need to go into such a feature. To date, nobody has volunteered. Note that if you use a "dynamic" relationship, i.e. a relationship() that loads every time, you will get the behavior you expect, provided you're using autoflush. This is how most other ORMs function regarding collections. However, they all have the disadvantage that collections load on every access, aren't at all capable of "eager loading" since they have no stored state, and have limited capability for collection manipulation. I'll add that last paragraph to the FAQ right now. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
