Hi,

Heard lots of good things about sqlalchemy and decided to give it a
try.
But almost immediately was confused by strange session.commit()
behavior, please look through following snippets.

Update is pretty straightforward:

>>> obj = MyModel.query.first()
>>> obj.attr
foo
>>> obj.attr = 'bar'
>>> session.commit()
>>> obj.attr
bar

And it works great, but when I need to update bunch of attrs from dict
first thought would be built-in vars function:

>>> obj.attr
bar
>>> kwargs = {'attr':'foo'}
>>> vars(obj).update(kwargs)
>>> obj.attr
foo
>>> session.commit()
>>> obj.attr
bar

Am I missing something?

Sure I could use obj.query.update(kwargs) but vars approach is good
pythonic pattern. Also I'm trying to keep SA away from logic.

Thanks,
Pavel

-- 
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.

Reply via email to