Re: [sqlalchemy] How to use make_transient() to duplicate an SQLAlchemy mapped object?

2015-05-23 Thread Mike Bayer
On 5/23/15 11:52 AM, c.bu...@posteo.jp wrote: Hi Mike, thanks for your help. On 2015-05-22 02:32 Mike Bayer mike...@zzzcomputing.com wrote: if you copy an object to transient, now instance_state.key is gone, next step is erase the primary key column-holding attributes, such as myobject.id =

Re: [sqlalchemy] don't lose the relationship() reference when calling make_transient()

2015-05-23 Thread Mike Bayer
On 5/23/15 12:30 PM, c.bu...@posteo.jp wrote: It cost me some time to analyse this problem. ;) The problem in the pseudo-code below is that 'obj' lose the reference to its foreign-key object (set with relationship()). The foreign key member itself is still correct set with a numeric value. I

[sqlalchemy] contains_eager does not load relation data if related model appears twice in query

2015-05-23 Thread Alex S
Hi everyone! I've found that contains_eager() does not load relation objects from query in case when related model appears twice in query. The working code with example models and steps to reproduce is listed in the attached file, I'll briefly describe the issue here. There are four models:

Re: [sqlalchemy] contains_eager does not load relation data if related model appears twice in query

2015-05-23 Thread Mike Bayer
On 5/23/15 5:45 PM, Alex S wrote: When I start printing some user's relations (u.preferences or u.accounts), I've found that all data was load via q.all() call and there are no additional queries in database. All data are loaded except for u.preferences.current_account.preferences. Account

Re: [sqlalchemy] contains_eager does not load relation data if related model appears twice in query

2015-05-23 Thread Mike Bayer
On 5/23/15 9:01 PM, Mike Bayer wrote: The best I can do is that there's a patch that can make this work but I definitely cannot commit it in 1.0; the eager loading mechanics are extremely sensitive and easily messed up by even the most subtle change, and I'd have to find time to think and

[sqlalchemy] don't lose the relationship() reference when calling make_transient()

2015-05-23 Thread c.buhtz
It cost me some time to analyse this problem. ;) The problem in the pseudo-code below is that 'obj' lose the reference to its foreign-key object (set with relationship()). The foreign key member itself is still correct set with a numeric value. I understand that this can happen because of the

Re: [sqlalchemy] don't lose the relationship() reference when calling make_transient()

2015-05-23 Thread c.buhtz
On 2015-05-23 18:30 c.bu...@posteo.jp wrote: I understand that this can happen because of the reference cycle counting stuff in the background of SQLA. But how can I prevent this? Maybe I should get into transaction handling with SQLA to prevent problems like this. ;) -- You received this

Re: [sqlalchemy] don't lose the relationship() reference when calling make_transient()

2015-05-23 Thread c.buhtz
On 2015-05-23 18:30 c.bu...@posteo.jp wrote: The problem in the pseudo-code below is that 'obj' lose the reference to its foreign-key object (set with relationship()). The foreign key member itself is still correct set with a numeric value. I tried load_on_pending=True but this doesn't help

Re: [sqlalchemy] How to use make_transient() to duplicate an SQLAlchemy mapped object?

2015-05-23 Thread c.buhtz
Hi Mike, thanks for your help. On 2015-05-22 02:32 Mike Bayer mike...@zzzcomputing.com wrote: if you copy an object to transient, now instance_state.key is gone, next step is erase the primary key column-holding attributes, such as myobject.id = None. object on flush will have no PK value