[sqlalchemy] Re: Pre-commit hooks

2008-05-15 Thread Yannick Gingras
Michael Bayer [EMAIL PROTECTED] writes: easy enough to build yourself a generic MapperExtension that scans incoming objects for a _pre_commit() method. Yeah indeed. I used this: -- class HookExtension(MapperExtension): Extention to add pre-commit hooks.

[sqlalchemy] Re: Pre-commit hooks

2008-05-15 Thread Roger Demetrescu
On 5/15/08, Yannick Gingras [EMAIL PROTECTED] wrote: Michael Bayer [EMAIL PROTECTED] writes: easy enough to build yourself a generic MapperExtension that scans incoming objects for a _pre_commit() method. Yeah indeed. I used this: -- class

[sqlalchemy] Re: Pre-commit hooks

2008-05-15 Thread az
speed wise, this is better: hasattr is implemented as getattr + try except. i would do it even: f = getattr(instance, _pre_insert, None) if f: f() Thus the func name is spelled only once - avoids stupid mistakes. On Thursday 15 May 2008 17:36:52 Roger Demetrescu wrote: On 5/15/08, Yannick

[sqlalchemy] Re: Pre-commit hooks

2008-05-15 Thread Roger Demetrescu
On 5/15/08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: speed wise, this is better: hasattr is implemented as getattr + try except. i would do it even: f = getattr(instance, _pre_insert, None) if f: f() Thus the func name is spelled only once - avoids stupid mistakes. Good point...

[sqlalchemy] Re: Pre-commit hooks

2008-05-15 Thread Yannick Gingras
[EMAIL PROTECTED] writes: speed wise, this is better: hasattr is implemented as getattr + try except. i would do it even: f = getattr(instance, _pre_insert, None) if f: f() Thus the func name is spelled only once - avoids stupid mistakes. Spelling only once is the killer feature of

[sqlalchemy] Re: Pre-commit hooks

2008-05-14 Thread Michael Bayer
On May 14, 2008, at 11:07 AM, Yannick Gingras wrote: Greetings Alchemists, Is it possible to define a hook in a mapped class that will be called to test the sanity of an instance before it gets committed? As an example: class Item(object): def _pre_commit(self): assert

[sqlalchemy] Re: Pre-commit hooks

2008-05-14 Thread King Simon-NFHD78
Yannick Gingras wrote: Greetings Alchemists, Is it possible to define a hook in a mapped class that will be called to test the sanity of an instance before it gets committed? As an example: class Item(object): def _pre_commit(self): assert (self.dry_weight +