Hi!
On Mon, Jan 05, 2015 at 12:19:20PM +0100, Gregor Horvath <gh...@gr...> 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/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|