On Feb 13, 2006, at 1:46 PM, Michael Bayer wrote:
dmiller wrote:
Hmm. Is there a test for that? I don't think my patch is causing it
to fail.
no theres no test for that as of yet....
OK. I've added one (patch attached).
wow and it works without the counter ? I totally cannot see how that
happens, as it seems like it calls "commit()" on a different
unitofwork
every time. But its just code....I hope to have a closer look later
today.
Clarification: it works on the code currently checked into SVN. I did
not try it on my previous patch. However, I think it should be
trivial to make my code work--just change the Session.commit method
to only commit the unitofwork if session.uow.parent is None.
I also noticed an ambiguity in begin/commit. This code:
>>> s = objectstore.get_session()
>>> # do stuff here
>>> s.commit()
is the same as:
>>> s = objectstore.get_session()
>>> s.begin()
>>> # do stuff here
>>> s.commit()
i.e. the first begin is "optional" if there will be no other begins/
commits in the "# do stuff here" portion. That's confusing. Is there
any way that we can remove this ambiguity? The problem is, it doesn't
matter how many times commit is called after the last begin. So code
like this:
def func(s):
s.begin()
# do stuff
s.commit() # save changes up to here
# do more stuff
s.commit() # save the remaining changes
works fine if it is not happening within an outer begin/commit. That
code becomes a problem when we do this:
s.begin()
func(s)
func(s)
s.commit()
i.e. changes are actually committed at the end of the first call to
func. However, no errors were reported and everything seemed to work
just fine. I think that's dangerous (even though the documentation
says it's illegal to have more commits than begins within "func"
there's nothing enforcing it which is deceptive). I think the only
way to get around this is to either force people to invoke begin
before every commit (cumbersome...bad API...what if they make changes
before calling begin?) or to have begin() return a new session object
to be used in the nested scope. Like this:
s1 = objectstore.get_session()
s2 = s1.begin()
# do stuff
s1.commit() # ERROR: uncommitted nested sessions
s2.commit() # not a real commit
s1.commit() # commit all changes including those made on s2
# do more stuff (all changes are now registered with s1)
s2.commit() # ERROR: session expired - parent session has been committed
s2 = s1.begin()
# do stuff
s2.commit() # ahh, that's better
s1.commit() # yeah, now you're getting it
Do you have any better ideas?
~ Daniel
-------------------------------------------------------
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