Hi Mike,
thanks for idea.
I am getting this exception : 
session.expire(test_run, [col.key for col in mapper.primary_keys])
AttributeError: 'InstanceState' object has no attribute 'primary_keys'

Do I need setup something on the schema objects in order to get this 
primary_keys?

right now I have this parameters on every relation in the objects in the 
schema  : 

lazy='joined',cascade="save-update, merge, delete, expunge")



Dňa štvrtok, 17. marca 2016 16:56:05 UTC+1 Mike Bayer napísal(-a):

>
> how about: 
>
>
> from sqlalchemy import inspect 
>
> mapper = inspect(obj) 
>
> session.expire(obj, [col.key for col in mapper.primary_keys]) 
> make_transient(obj) 
>
>
>
> On 03/17/2016 10:54 AM, milan5...@gmail.com <javascript:> wrote: 
> >     Right now I am taking  test run object from local database, then I 
> >     call expunge on that object (cascade is set to expunge). 
> > 
> >   then I put this object into this python method : 
> > 
> > def _reset_primary_keys(self, test_run): 
> > make_transient(test_run) 
> > test_run.ID= None 
> >      if test_run.OrderNumber: 
> > make_transient(test_run.OrderNumber) 
> > test_run.OrderNumber.ID= None 
> > 
> >      for equipmentin test_run.TestEquipments: 
> > make_transient(equipment) 
> > equipment.ID= None 
> > 
> >      for trdin test_run.TestRunToDevs: 
> > make_transient(trd) 
> > trd.ID= None 
> > 
> >          if trd.TestedDut: 
> > make_transient(trd.TestedDut) 
> > trd.TestedDut.ID= None 
> > 
> >          for test_stepin trd.TestSteps: 
> > make_transient(test_step) 
> > test_step.ID= None 
> > 
> >              for test_resultin test_step.TestResults: 
> > make_transient(test_result) 
> > test_result.ID= None 
> > 
> > 
> > This method reset all primary keys, so I can merge it into master 
> > database which will generate new primary keys. Is there a better or 
> > easier way how to do it? 
> > 
> > -- 
> > 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 to sqlalchemy+...@googlegroups.com <javascript:> 
> > <mailto:sqlalchemy+unsubscr...@googlegroups.com <javascript:>>. 
> > To post to this group, send email to sqlal...@googlegroups.com 
> <javascript:> 
> > <mailto:sqlal...@googlegroups.com <javascript:>>. 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to