[EMAIL PROTECTED] wrote: > > On Monday 20 August 2007 18:09:41 jason kirtland wrote: >> svilen wrote: >> > And anyway i need to first create the object and just then >> > append it (the decorators will first fire event on the object >> > and just then append(), that is call me), so may have to look >> > further/deeper. Maybe i can make my append create objects first >> > and then call the actual appender - so yes, this is the way. >> >> Either way. The @internally_instrumented is there exactly for >> that flexibility on ORM interface methods like 'append' and as an >> override for ABC decoration on python interface methods. (The >> regular recipes also override ABC decoration.) Or you can do >> you work elsewhere and forward to an instrumented method for >> event service. > an example on this? i can't figure it out, whatever i do, that > ABC-auto-decorators loop kicks in and byebye my nice append - > even if the appender is not append() at all.
For your example, something like: class MyCollection(list): @collection.internally_instrumented def append(self, options, **kw): # do factory stuff, forward to _append new_obj = factory_stuff(options, **kw) # forward to _append, which will fire events self._append(new_obj) @collection.appender def _append(self, item): ... But tacking a factory method onto a regular Python list is much simpler with a separation of concerns: class FactoryCollection(list): def create(self, options, **kw): obj = factory_stuff(options, **kw) self.append(obj) return obj No decorators needed. For a while there was a "no-op" decorator that did the same job as @internally_instrumented in the first example, just a different name for clarity. It could easily come back if this pattern becomes common- I yanked it after working with the collections for a while and finding the second form much more common in my work. > Why should append() be instrumented regardless of it being or > not the used appender? If you use an object with a Python list interface, all the list interface methods will be instrumented so that relation collections have natural Pythonic behavior. If you don't want automatic instrumentation on list methods you don't have to have it- see the 0.4 docs for how to opt out via __emulates__. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---