Skip to content

Get fails with "writable buffers not hashable" when run in a separate session. #390

@ichorid

Description

@ichorid

Issue #355 is not solved completely, I can still trigger it when the object creation and get are in different sessions, and unique buffer is an optional field.

from pony import orm
from pony.orm import db_session

db = orm.Database()
class Bla(db.Entity):
    smt = orm.PrimaryKey(int, auto=True)
    opt = orm.Optional(buffer, unique=True)
db.bind(provider='sqlite', filename=':memory:')
db.generate_mapping(create_tables=True)
with db_session:
    a = Bla(opt=buffer("123"))
    q = orm.select(p for p in Bla)[:]
    a_smt = q[0].smt

with db_session:
    b = Bla.get(smt=a_smt)
  File "./pony_bug_buffer.py", line 16, in <module>
    b = Bla.get(smt=a_smt)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 3768, in get
    try: return entity._find_one_(kwargs)  # can throw MultipleObjectsFoundError
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 3867, in _find_one_
    if obj is None: obj = entity._find_in_db_(avdict, unique, for_update, nowait)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 3927, in _find_in_db_
    objects = entity._fetch_objects(cursor, attr_offsets, 1, for_update, avdict)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 4059, in _fetch_objects
    obj._db_set_(avdict)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 4613, in _db_set_
    cache.db_update_simple_index(obj, attr, old_val, new_dbval)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 1854, in db_update_simple_index
    obj2 = cache_index.setdefault(new_dbval, obj)
TypeError: writable buffers are not hashable

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions