Hi!

On Mon, Jan 05, 2015 at 12:19:20PM +0100, Gregor Horvath 
<g...@gregor-horvath.com> wrote:
> Problem: 
> 
>     raise SQLObjectNotFound, "The object %s by the ID %s does not
>  exist" % (self.__class__.__name__, self.id)
> sqlobject.main.SQLObjectNotFound: The object Eingangsrechnung by the ID
> 1 does not exist
> 
> --------------------
> 
> sqlhub.processConnection.autoCommit = False
> t = Person._connection.transaction()
> er = Eingangsrechnung(name="test")
> pr = Person(name="test")
> Buchung(person=pr, eingangsrechnung=er)
> t.commit()
> 
> ----
> Greg

   With SQLObject you can open a dozen different connections to the same
or different backends. Because of that you have to explicitly set your
desired connection for any select/create operation (after select/create
the object remembers its connection and uses it for update/delete); if
you don't set connection explicitly sqlhub is used.
   Creating a transaction doesn't automatically use that transaction --
you have to use the new transaction object as a connection. So your
options are:

1. Assign the transaction to sqlhub:

the new t = Person._connection.transaction()
sqlhub.processConnection = t # <= !!!
er = Eingangsrechnung(name="test")
pr = Person(name="test")
Buchung(person=pr, eingangsrechnung=er)
t.commit()

   Don't forget to set the original connection back at the end:

sqlhub.processConnection = initialConnection

2. Use the transaction explicitly:

t = Person._connection.transaction()
er = Eingangsrechnung(name="test", connection=t)
pr = Person(name="test", connection=t)
Buchung(person=pr, eingangsrechnung=er, connection=t)
t.commit()

3. Rewrite you code as a function and use sqlhub.doInTransaction(f);
doInTransaction creates and commits a transaction for you, no need to
create t.

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            p...@phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to