pythonoracle-databasecx-oracleponyormpony

Python 3.6 with pony 0.7 gives error on commit to oracle db


I am using pony and python with above mentioned versions. I am trying to do an insert by referring https://docs.ponyorm.com/firststeps.html

commit()

gives the following error:

type error : unhashable type: 'list'

This comes from:

obj2 = cache_index.setdefault(new_id, obj) in _save_created_

This is my Code :

from pony.orm import Database
from pony.orm import db_session
from pony.orm import commit 
from pony.orm import Required
from pony.orm import show
from pony.orm import Set
from pony.orm import set_sql_debug
from pony import orm
db = Database()

class Person(db.Entity):
    name = Required(str)
    age = Required(int)
    cars = Set('Car')

class Car(db.Entity):
    make = Required(str)
    model = Required(str)
    owner = Required(Person)

show(Person)

db.bind(provider='oracle',user='myuser',password='mypassword', 
dsn='localhost:1521/xe')
db.generate_mapping(create_tables=True)
set_sql_debug(True)
p1 = Person(name='John', age=20)
p2 = Person(name='Mary', age=22)
p3 = Person(name='Bob', age=30)
c1 = Car(make='Toyota', model='Prius', owner=p2)
c2 = Car(make='Ford', model='Explorer', owner=p3)
commit()

my python version is 3.6.1 and my oracle version is 11g Express Edition Release 11.2.0.2.0 - 64bit Production

And this is the full traceback

p1 = Person(name='John', age=20)
p2 = Person(name='Mary', age=22)
p3 = Person(name='Bob', age=30)
c1 = Car(make='Toyota', model='Prius', owner=p2)
c2 = Car(make='Ford', model='Explorer', owner=p3)
commit()
GET CONNECTION
INSERT INTO "PERSON" ("NAME", "AGE") VALUES (:p1, :p2) RETURNING "ID" INTO :new_id
{'p1':'John', 'p2':20}

ROLLBACK
RELEASE CONNECTION
Traceback (most recent call last):

File "<ipython-input-5-d37ff54adaa6>", line 6, in <module>
commit()

File "<string>", line 2, in commit

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\utils\utils.py", line 78, in cut_traceback
reraise(exc_type, exc, full_tb)

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\utils\utils.py", line 95, in reraise
try: raise exc.with_traceback(tb)

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\utils\utils.py", line 61, in cut_traceback
try: return func(*args, **kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\orm\core.py", line 337, in commit
rollback_and_reraise(sys.exc_info())

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\orm\core.py", line 326, in rollback_and_reraise
reraise(*exc_info)

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\utils\utils.py", line 95, in reraise
try: raise exc.with_traceback(tb)

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\orm\core.py", line 335, in commit
cache.flush()

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\orm\core.py", line 1797, in flush
if obj is not None: obj._save_()

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\orm\core.py", line 5090, in _save_
if status == 'created': obj._save_created_()

File "C:\ProgramData\Anaconda3\lib\site-packages\pony\orm\core.py", line 4943, in _save_created_
obj2 = cache_index.setdefault(new_id, obj)

TypeError: unhashable type: 'list'  

Solution

  • It looks like you've hit this bug in Pony ORM.

    The bug appears to have been fixed in the source repository some time last month, but at the time I write this answer, this fix isn't available in a release. The most recent release of Pony ORM is currently version 0.7.6, released in August 2018.

    As the bug relates to a breaking change in cx_Oracle 7, your best bet is probably to downgrade to version 6 of cx_Oracle. (I've got version 6.3.1 installed, which probably explains why I couldn't reproduce your error.)