Python 3.6 with pony 0.7 在提交到 oracle db 时出错

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

我在上面提到的版本中使用 pony 和 python。 我正在尝试通过引用 https://docs.ponyorm.com/firststeps.html

来插入

commit()

出现以下错误:

type error : unhashable type: 'list'

本文来自:

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

这是我的代码:

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()

我的 python 版本是 3.6.1,我的 oracle 版本是 11g Express Edition Release 11.2.0.2.0 - 64bit Production

这是完整的回溯

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'  

看来你已经达到了 this bug in Pony ORM

该错误似乎已在上个月的某个时间在源存储库中得到修复,但在我撰写此答案时,此修复程序在发行版中不可用。目前 Pony ORM 的最新版本是 0.7.6 版本,于 2018 年 8 月发布。

由于该错误与 cx_Oracle 7 中的重大更改有关,您最好的选择可能是降级到 cx_Oracle 的版本 6。 (我已经安装了 6.3.1 版本,这可能解释了为什么我无法重现您的错误。)