Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An attempt to mix objects belonging to different transactions

Tags:

orm

ponyorm

pony.orm.core.TransactionError: An attempt to mix objects belonging to different transactions

I know that this error is descriptive, I just can't figure out WHY its occurring. I have searched google, the docs, other SO posts, and found nothing.

Any ideas?

like image 569
Andrew Graham-Yooll Avatar asked Oct 16 '25 13:10

Andrew Graham-Yooll


1 Answers

This error arises if somebody attempts to interlink two objects which belongs to identity maps of two different db sessions:

from pony.orm.examples.university1 import *

populate_database()

with db_session:
    g = Group[101]

with db_session:
    s = Student[4]
    s.group = g  # or g.students.add(s)

Each db session should work with objects retrieved within this db session only. If you need to store some information between db sessions, you can store object's id value instead of object itself. Also you can pickle objects in one db_session and then unpickle them in another db_session.

like image 149
Alexander Kozlovsky Avatar answered Oct 19 '25 13:10

Alexander Kozlovsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!