On Jan 14, 2014, at 5:44 PM, [email protected] wrote:

> I have discovered something interesting...
> 
> (Pdb) db.session.refresh(fresh_profile)
> (Pdb)
> 
> (Pdb) db.session.refresh(cache_profile)
> *** InvalidRequestError: Instance '<Profile at 0x1075e2b90>' is not 
> persistent within this Session
> 
> So the status of my cached instance is something other than persistent (is 
> there a method to check this?). My theory is that relationship query won't 
> fire because it believes it isn't yet saved to the db.
> 
> http://docs.sqlalchemy.org/en/latest/orm/session.html#quickie-intro-to-object-states

yes, inspect() will get you all that

inspect(my_object).persistent

http://docs.sqlalchemy.org/en/rel_0_9/orm/internals.html#sqlalchemy.orm.state.InstanceState.persistent




> 
> On Tuesday, January 14, 2014 5:26:19 PM UTC-5, Michael Bayer wrote:
> 
> On Jan 14, 2014, at 4:36 PM, [email protected] wrote: 
> 
> > Help! 
> > 
> > I'm employing a cache strategy which saves Model instances to an in-memory 
> > store. When I retrieve these instances from the cache, I add them to my 
> > session. All the data is there, but when I try to use a relationship 
> > property it returns None. 
> 
> “use”, like, my_instance.some_other_object returns None?   What kind of SQL 
> output do you see when you hit that attribute?  How is “my_instance” being 
> created in the first place? 
> 
> 
> > 
> > A test with two objects: cache_obj and fresh_obj, the only difference I see 
> > is that one has a unicode string for it's foreign key and the other does 
> > not (which is also strange). 
> > 
> > (Pdb)  fresh_obj_map.attrs['profile'].target == 
> > cache_obj_map.attrs['profile'] 
> > True 
> > 
> > (Pdb) cache_obj.profile_id 
> > '2cedffc2-7d5c-11e3-8cb0-c82a1412a8b6' 
> > 
> > (Pdb) fresh_obj.profile_id 
> > u'2cedffc2-7d5c-11e3-8cb0-c82a1412a8b6' 
> > 
> > (Pdb) cache_obj.profile 
> > 
> > (Pdb) fresh_obj.profile 
> > <alphaworks.models.profile.Profile object at 0x10215e910> 
> 
> if profile_id is a string column all the way then the u’’ ‘’ difference 
> shouldn’t be much of an issue. 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to