On Sat, Feb 19, 2011 at 03:28, Michael Bayer <[email protected]> wrote: > So there is attributes.get_history(obj, key) as the public API, so you don't > have to mess around with states and dicts and such. It accepts an argument > "passive" which when passed the symbol attributes.PASSIVE_NO_INITIALIZE will > not fire off any lazy callables, including those collections you don't want > to load.
Ah, so that's the part I need. Thank you! :) I've spent a lot of time poking in the internals of sqla... no idea how I've managed to overlook "passive". :( > things you don't need: > > - the check there for hasattr(attr.impl, 'get_history'), every impl > has 'get_history' , "impl" isn't exactly public API anyway Well, general idea of my code were taken from http://hg.sqlalchemy.org/sqlalchemy/file/dc1d5fe2e63b/lib/sqlalchemy/orm/session.py#l1606 So maybe it just need to be updated? :-) > - defensive "dictionary changed size" thing - I can't really think of > how the manager's size changes in that loop, even > if a mapper configure fires off, the manager already has all the attributes > in it...send me a stack trace on that Ok, I will in case if I'll get another one. > - ValueError when you call attr.impl.get_history() ? no idea why > you'd get a ValueError there. we call history all > over the place, I use it in applications for versioning, and there are no > ValueErrors I suppose this was (is?) some bug in our application. Not sure though, that was a quick fix-live-asap bug. :) > now as far as speed, using the higher level APIs introduces a little more > function call overhead due to fetching "state" and "dict" for each attribute, > though this is negligible for most use cases. using impl.get_history() with > state and dict as you are would work similarly, also accepts "passive". Sure, thanks a lot! I've measured their performance, it seems that using higher level APIs is twice as slow as using impl.get_history(), but that is like 30us vs 60us, which is not that important. :) -- Alexander -- 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.
