On May 25, 2010, at 5:06 AM, Torsten Landschoff wrote:

> 
> assert not session.is_active
> d1 = Data()
> d1.name = "an_entry"
> session.add(d1)
> # -> I would expect an exception here as we are outside of any
> # transaction!
> 
> with session.begin():
>    d2 = Data()
>    d2.name = "another_entry"
>    session.add(d2)
> 
> # This will fail as there are two entries now.
> session.query(Data).one()
> -----
> 
> 
> Is there a supported way to enforce explicitly starting a transaction
> before adding or updating any persistent objects?


I suppose you could try subclassing Session or perhaps seeing if the hooks 
provided with SessionExtension (I'm thinking the attach hook) give you enough 
to go on here.   Or, probably easier, just build yourself a wrapper class that 
looks like Session but proxies requests to it, after passing through your 
checks for current transaction active.

It should go without saying that Clojure is from an entirely different 
philosophy than that of Python and SQLAlchemy (its author is hostile to the 
entire concept of object oriented design), so imitating particular behaviors of 
Clojure is not a core goal of the project.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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