Great, now it works. :-)
Thank you very much, Michael.

j

Michael Bayer ha scritto:
> use the connection object passed to the before_update() method to  
> execute all SQL.   do not use "implicit execution" as you are doing  
> (i.e. the execute() method on ClauseElements).   the usage of multiple  
> connections is likely creating a deadlock, and in any case violates  
> the integrity of the transaction.
>
>
> On Mar 7, 2009, at 1:26 PM, jo wrote:
>
>   
>> Hi all,
>>
>> I have a strange behavior using MapperExtension before_update.
>> I created two tables; anag and azi, azi have a foreign key to anag.
>> When I try to change some column value on anag table the
>> HistoryAnag.before_update is correctly triggered and it returns  
>> EXT_PASS,
>> but when I try to change some column value on both tables the
>> HistoryAnag.before_update is correctly triggered and it returns  
>> EXT_PASS
>> then HistoryAzie.before_update is triggered but it stucks and it do  
>> not
>> returns EXT_PASS, it goes in loop somewhere.
>> I'm using SQLAlchemy 0.3.10 and turbogears 1.0.3.2
>>
>> Is there someone experimenting some behavior?
>> -----------------------------------------------------------------------------------
>>  anag=Table('anag',database.metadata,
>>        Column('id', Integer, Sequence('anag_seq'), primary_key=True,
>> nullable=False),
>>        Column('name', Unicode(200), nullable=False, index=True),
>>        Column('id_prec', Integer),
>>        Column('status', Unicode(1), PassiveDefault('A'))
>>     )
>>
>>  azi=Table('azi',database.metadata,
>>        Column('id', Integer, Sequence('azi_seq'), primary_key=True,
>> nullable=False),
>>        Column('id_anag', Integer, nullable=False),
>>        Column('id_prec', Integer),
>>        Column('status', Unicode(1), PassiveDefault('A')),
>>        ForeignKeyConstraint(['id_anag'],['anag.id'])
>>        )
>>
>>
>> from sqlalchemy.orm import MapperExtension, EXT_PASS
>> class HistoryAnag(MapperExtension):
>>    def __init__(self):
>>        MapperExtension.__init__(self)
>>        self.methods = ('before_update',)
>>
>>    def before_update(self, mapper, connection, instance):
>>        from turbogears import identity
>>        rec = anag.select(anag.c.id ==
>> instance.anag_id).execute().fetchone()
>>        dd=dict(rec)
>>        dd.pop('id',None)
>>        dd['status'] = 'M'
>>        ret = anag.insert(values=dd).execute()
>>        lastid = ret.last_inserted_ids()[0]
>>        instance.anag_id_prec = lastid
>>        return EXT_PASS
>> class Anag():
>>      pass
>> assign_mapper(context,
>>              Anag,
>>              anag,
>>              extension=HistoryAnag()
>>              )
>>
>> class HistoryAzi(MapperExtension):
>>    def __init__(self):
>>        MapperExtension.__init__(self)
>>        self.methods = ('before_update',)
>>
>>    def before_update(self, mapper, connection, instance):
>>        from turbogears import identity
>>        rec = azi.select(azi.c.id ==  
>> instance.azi_id).execute().fetchone()
>>        dd=dict(rec)
>>        dd.pop('id',None)
>>        dd['status'] = 'M'
>>        ret = azi.insert(values=dd).execute()
>>        lastid = ret.last_inserted_ids()[0]
>>        instance.azi_id_prec = lastid
>>        return EXT_PASS
>>
>> class Azi():
>>      pass
>> assign_mapper(context,
>>              Azi,
>>              azi,
>>              extension=HistoryAzi()
>>              )
>>
>> Thank you for any help.
>> j
>>
>>
>>     
>
>
> >
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to