On Feb 28, 2012, at 6:08 PM, Kent wrote:
On Feb 28, 5:39 pm, Michael Bayer mike...@zzzcomputing.com wrote:
oh also you might want to use attributes.set_committed_state instead of
setattr() so that the history is cleared.
1) What do you mean? setattr() also clears the history if you set it
back to what it used to be... right?
er not totally we don't compare the two values to determine no change until
within the flush. that is, if you have an object, and self.x is 5 if you say
self.x = 5 that fires off a modified event, state remains until those values
are compared later on.
2) yes, I meant not going back to database, so given I need to
manually reset them, is there a more elegant method than:
for col in object_mapper(self).iterate_properties:
if type(col) is ColumnProperty and \
type(col.columns[0]) is Column:
...
# find and set orig_value
...
setattr(self, col.key, orig_value)
I'd probably go into InstanceState.manager to get at the keys, then just look
at uses_objects to get at scalars, ticket #2208 has some ideas to make a real
public API out of this, though it's focused on readonly attributes...
state = instance_state(obj)
modified_keys = []
for key in state.manager:
attr = state.manager[key].impl
if not impl.uses_objects and key in state.committed_state:
state.dict[key] = state.committed_state[key]
modified_keys.append(key)
state.commit(state.dict, modified_keys)
--
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.