[sqlalchemy] Re: obtaining previous value in mapper.extension.after_*
On Dec 16, 2007, at 3:26 PM, [EMAIL PROTECTED] wrote: and another issue around attribute.get_history... i have a descriptor that is autosetting some defaultvalue at first get. a descriptor on top of the InstrumentedAttribute itself ? id wonder how you are configuring that. ScalarObjectAttributeImpl never knows that the attribute has been missing at start - dict.get(key,NOVALUE) will never return NOVALUE, as the descriptor machinery is called instead of __dict__[key] / haskey etc. if you really want a default on first get value, and youre riding directly on top of the IA instead of using a differently-named attribute for your own descriptor like all the docs say to do, you should use the callable mechanisms built into the attributes package, although the new value created becomes the committed state so maybe thats not what you want. im confused, someone issues print object.foo, then it inserts some new data instead of not doing anything ? what if nobody gets the attribute ? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: obtaining previous value in mapper.extension.after_*
Michael Bayer wrote: On Dec 16, 2007, at 3:26 PM, [EMAIL PROTECTED] wrote: and another issue around attribute.get_history... i have a descriptor that is autosetting some defaultvalue at first get. a descriptor on top of the InstrumentedAttribute itself ? id wonder how you are configuring that. under IA. in the __dict__ (which is not a dict at all). ScalarObjectAttributeImpl never knows that the attribute has been missing at start - dict.get(key,NOVALUE) will never return NOVALUE, as the descriptor machinery is called instead of __dict__[key] / haskey etc. if you really want a default on first get value, and youre riding directly on top of the IA instead of using a differently-named attribute for your own descriptor like all the docs say to do, yes and no, as i said i'm replacing the __dict__ with something special; so its IA riding on top of me (;-) but otherwise its that. no renaming, i dont want someone (thats can be me, later) to be able to workaround either me or SA. you should use the callable mechanisms built into the attributes package, although the new value created becomes the committed state so maybe thats not what you want. im confused, someone issues print object.foo, then it inserts some new data instead of not doing anything ? what if nobody gets the attribute ? then it remains unset (None, null, whatever). and i have a.b.c.d = 3 where b and c are auto-created (if declared so of course) as for autoinsert -- what people write is what people get. i know it may be confusing; its a sort of declarative attribute-type metainfo, with validation, conversion, readonly, autoset, default-value, optional'ism, hints about UI/str/whatever representation, comment etc etc). And static-typing/static-attribute-set of course. db-business objects should not have any random stuff hanging on them. trouble is it partialy duplicates some SA features so there is a conflict of interests, since day one of their meeting. i was thinking about splitting it into two and putting one part above IA using those renamed columns approach and the rest underneath but that would be lots of work. later svilen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: obtaining previous value in mapper.extension.after_*
yes and no, as i said i'm replacing the __dict__ with something special; so its IA riding on top of me (;-) but otherwise its that. no renaming, i dont want someone (thats can be me, later) to be able to workaround either me or SA. then have your magic __dict__ implement the same save committed on change behavior as the attributes package. and of course test on every SA release (i know, it broke only 6 times this year ;-) since youre welded to internal behavior: def my_magic_dict_set_something(dict, key, value): if key not in dict['_state'].committed_state: dict['_state'].committed_state[key] = _the_old_value dict[key] = value thanks, thats different idea to what i had in mind... i'll try.. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: obtaining previous value in mapper.extension.after_*
[EMAIL PROTECTED] wrote: i used to get the original (before change) value of some attribute via state.commited_state[key]... but seems now that dict is empty at the time when ext.after_* are called. any way to get that? storing copies at ext.before_* is not good alternative... found some workaround but not sure if it's proper thing: r = getattr( instance.__class__, attribute).get_history( instance) r = r[-1] or r[-2] return r and r[0] or None #should never be None ??? not sure what the three get_history sublists are for... --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: obtaining previous value in mapper.extension.after_*
On Dec 16, 2007, at 2:33 PM, [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: i used to get the original (before change) value of some attribute via state.commited_state[key]... but seems now that dict is empty at the time when ext.after_* are called. any way to get that? storing copies at ext.before_* is not good alternative... found some workaround but not sure if it's proper thing: r = getattr( instance.__class__, attribute).get_history( instance) r = r[-1] or r[-2] return r and r[0] or None#should never be None ??? not sure what the three get_history sublists are for... (added, unchanged, deleted) = attributes.get_history(myinstance._state, 'someattribute') three lists will never be None unless you call get_history() with passive=True and lazyload would be needed. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: obtaining previous value in mapper.extension.after_*
and another issue around attribute.get_history... i have a descriptor that is autosetting some defaultvalue at first get. before r3935 it was ok; now the atribute is not updated anymore (in exact case, another object has to be inserted but it is not) as it seems that ScalarObjectAttributeImpl never knows that the attribute has been missing at start - dict.get(key,NOVALUE) will never return NOVALUE, as the descriptor machinery is called instead of __dict__[key] / haskey etc. i am looking at _create_history() and the way it is used but see no light... as i do not know either was there a value or not... well the object is brand new so it has to have nothing... Any way to hint it? so some just-created object would have an initialy empty history. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: obtaining previous value in mapper.extension.after_*
On Dec 16, 2007, at 3:16 PM, [EMAIL PROTECTED] wrote: not sure what the three get_history sublists are for... (added, unchanged, deleted) = attributes.get_history(myinstance._state, 'someattribute') three lists will never be None unless you call get_history() with passive=True and lazyload would be needed. in a scalar context, what (added, unchanged, deleted) mean? setattr-added delattr-deleted ? so the old value is (deleted or unchanged)[0]? i have really nice unit tests now that illustrate the whole thing in test/orm/attributes.py HistoryTest: attributes.register_class(Foo) attributes.register_attribute(Foo, 'someattr', uselist=False, useobject=False) f = Foo() self.assertEquals(attributes.get_history(f._state, 'someattr'), ([], [], [])) f.someattr = hi self.assertEquals(attributes.get_history(f._state, 'someattr'), (['hi'], [], [])) f._state.commit(['someattr']) self.assertEquals(attributes.get_history(f._state, 'someattr'), ([], ['hi'], [])) f.someattr = 'there' self.assertEquals(attributes.get_history(f._state, 'someattr'), (['there'], [], ['hi'])) f._state.commit(['someattr']) self.assertEquals(attributes.get_history(f._state, 'someattr'), ([], ['there'], [])) del f.someattr # oops, svn up to r3952 self.assertEquals(attributes.get_history(f._state, 'someattr'), ([], [], ['there'])) if the attribute is an object reference, you might have [None] instead of [] for added/unchanged if theres no value. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---