14 May 17:25
Re: Pre-commit hooks
From: Michael Bayer <mike_mp <at> zzzcomputing.com>
Subject: Re: Pre-commit hooks
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-14 15:25:48 GMT
Subject: Re: Pre-commit hooks
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-14 15:25:48 GMT
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 (self.dry_weight + self.fluids) < 50 > mapper(Item, items_table) > > I don't want to put the test mutators of dry_weight or fluids since > it's OK to have a temporary inconsistent state as long as the state is > consistent at commit time. > > I see that some of this functionality if covered by MapperExtention > but since the test is only related to Item I'd rather put the test in > it. > easy enough to build yourself a generic MapperExtension that scans incoming objects for a "_pre_commit()" method. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy <at> googlegroups.com To unsubscribe from this group, send email to sqlalchemy-unsubscribe <at> googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
RSS Feed