On 12/15/2011 1:31 PM, Michael Bayer wrote:
Are there reasons one need to avoid referencing unloaded relationships from 
within before_upate()?  (I can't recall the exact problem I've had in the past 
with that at the moment.)

Thanks for all the input. Regarding the issue of referencing a relationship from within before_update()/before_insert(), etc. I looked up my previous problem and it is related to this code from strategies.py:

class LazyLoader()
...
def _load_for_state(self, state, passive):
...
        if self.use_get:
            if session._flushing:
get_attr = instance_mapper._get_committed_state_attr_by_column
            else:
                get_attr = instance_mapper._get_state_attr_by_column

If we are in the middle of a flush, we don't attempt a query but rather use the committed state. This caused me problems when the committed state of the relationship was "None" (for example, not loaded yet?)

For my own understanding, what implications does this have? It kind of freaked me out because I interpreted that as meaning "I'm not sure if I can rely upon unloaded relationships at all from within these mid-flush event methods..." because I certainly don't want to be using stale, old data. Is there a threat of this, or only of it sometimes being "None"?


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

Reply via email to