yah just do objectstore.uow().rollback(), I guess I didnt put the
convenience method in for that.
Also, I think with rollback() at the moment, you have to do this idea:
objectstore.begin()
try:
# load, modify objects
except:
objectstore.rollback()
raise
objectstore.commit()
That should probably be changed to allow rollback() without the begin
(), since theres always sort of an "intrinsic begin" in place.
I am not super-thrilled about the objectstore.rollback() idea, since
its just going to take all the changes youve made to your objects in
memory, and roll them back to what they were orignially. I suspect
this funcitonality is not complete by itself, i.e. what happens to
objects that were "new" ?, etc., but also if your objects have other
state information that is linked to those attributes, that state
information doesnt get rolled back as well, since SA doenst know
anything about your extra object state. this is why i havent pushed
the concept. But, it might work for what you are doing.
So the safer way is more like this:
try:
# load, modify objects
except:
# totally clean out the current map of objects
objectstore.clear()
raise
objectstore.commit()
which basically means, somehting went wrong, so throw away the whole
loaded map of everything and start all over again. however this
might not work with your GUI-oriented idea.
You also might look into "rolling back" objects one by one, like this:
objectstore.rollback_obj(myobj)
which just restores whatever in-memory changes youve made on 'myobj'
back to the object's loaded state.
also, theres no need to do the 'engine.commit()' 'engine.rollback()'
step, the database transaction is handled within the
objectstore.commit() operation.
I am going very slow on the docs for objectstore since i also havent
gotten my head around how i want to explain it, and also im not sure
what the best practices should be with regards to rolling back etc.
so if you look into the various options above, let me know your
experiences !
- mike
On Jan 21, 2006, at 3:57 PM, Robin Munn wrote:
I haven't quite wrapped my head around how mapping/objectstore.py
works yet, and its documentation is still unfinished, so I think my
best bet is to ask here.
I'm writing a toy application to get used to using SQLAlchemy in
"real" work. I have a GUI dialog that presents data to the user, and I
want him to be able to fill it out and click either OK to save the
data or Cancel to cancel his changes and leave the database untouched.
The text fields in the dialog all have event handlers that catch a
lose-focus event (such as tabbing away from the control), check
whether they've been modified, and if so, update the mapped-table
object (by doing "setattr(self.data_record, column.name,
ctrl.GetValue())"). The dialog's event handlers for the OK and Cancel
buttons look like this:
def OnOK(self, event):
log.info("Saving...")
objectstore.commit()
engine.commit()
event.Skip() # Let the event propagate up to the standard
handler
def OnCancel(self, event):
log.info("Reverting...")
objectstore.commit()
engine.rollback()
event.Skip() # Let the event propagate up to the standard
handler
(I call engine.begin() when the dialog is first presented to the
user).
That seems to work, but the OnCancel handler is bugging me. Doing
objectstore.commit() followed immediately by engine.rollback() seems
wrong. I'd like to have an objectstore.rollback() method, but I don't
see one. Should I call objectstore.uow().rollback()? Would that do
what I'm looking for?
This is probably really simple, but I just don't have my head wrapped
around the unit of work system yet.
--
Robin Munn
[EMAIL PROTECTED]
GPG key
0xD6497014-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through
log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD
SPLUNK!
http://sel.as-us.falkag.net/sel?
cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users