install_state is normally called during __init__ of your object. the attributes package decorates __init__ for this purpose. so you have to get __init__, or __new__, or whatever, to ensure that attributes.instance_state(obj) will return an InstanceState at all times.
On Feb 7, 2009, at 10:02 PM, Christiaan Putter wrote: > > Thanks for the link. That's where I figured out most of what I'm > trying to do. > > Now that I've stepped through the code I noticed that 'install_state' > is only being called on the first 2 iterations of the loop. Haven't > found out yet why that is. > > What exactly is supposed to be in the state? Is an instance.__dict__ > supposed to be identical to that of state.dict? It seems that after > a commit that state.dict is cleared so I'm guessing it's only used for > dirty attributes. For some reason after the commit instance.__dict__ > gets modified and the attributes that have been updated get cleared, > only for the first two iterations though. > > I changed the loop to look like: > > sess = sqlservice.Session() > for per in people: > obj = User(name=per) > sess.add(obj) > print obj > sess.commit() > sess.close() > > > which behaves the way one would expect... So I'm guessing it must be > in the way I'm storing the state right? At the moment the > InstrumentationManager stores the states in a dict self.states. So I > tried to rewrite it to store it directly on the instance, say > instance.__sa_state__, but that doesn't work. When add gets called, > install_state hasn't been called yet. Is that supposed to be that > way? Maybe my instances aren't getting instantiated correctly. > > This is becoming really confusing. I'm taking a quick smoke break. > > > --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---