On Dec 27, 2011, at 5:21 PM, Kent wrote:

>> So see what happens if you, for the moment, just monkeypatch over 
>> orm.session._state_session to do a lookup in a global context if 
>> state.session_id isn't set.  If that solves the problem of "I want detached 
>> objects to load stuff", for you and everyone else who wants this feature, 
>> then whatever - I'm not at all thrilled about this use case but if it's just 
>> one trivial hook that I don't need to encourage, then there you go.
>> 
> 
> Please give me a lesson in monkeypatching 101.  This isn't being
> invoked:
> 
> =====================
> import sqlalchemy.orm.session as session_module
> sqla_state_session = session_module._state_session
> def _state_session(state):
>    """
>    for transient/detached objects, so we can automatically query
> these related objects
>    """
>    return sqla_state_session(state) or DBSession()
> setattr(session_module, '_state_session', _state_session)
> =====================
> 
> I presume there are already references to _state_session before I
> change it.

Hm I would have guessed, but mapper.py and strategies.py seem to be calling it 
relative to the module.   What does pdb tell you if you post mortem into where 
it raises the Detached error ?

> 
> Also, will this cause other side effects, such as obj in DBSession
> reporting True when it used to report False or the orm internals being
> confused by the return of this value?

maybe ?  if it doesn't just work then yes.  The new logic here only needs to 
take place at the point at which it loads an attribute so if we made it local 
to those areas, there shouldn't be any big issues.

I'm basically making you a developer here to help me test this out.


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