0

我正在使用上述版本的小马和蟒蛇。我正在尝试通过引用https://docs.ponyorm.com/firststeps.html进行插入

犯罪()

给出以下错误:

类型错误:不可散列类型:“列表”

这来自:

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'  
4

1 回答 1

0

看起来你在 Pony ORM 中遇到了这个错误

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

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

于 2019-01-03T22:04:59.903 回答