New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ichorid opened this Issue Oct 12, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@ichorid
Copy link

ichorid commented Oct 12, 2018

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

@ichorid ichorid changed the title Get fails with "writable buffers not hashable" when run in separate session. Get fails with "writable buffers not hashable" when run in a separate session. Oct 12, 2018

@kozlovsky kozlovsky added the bug label Oct 16, 2018

@kozlovsky kozlovsky self-assigned this Oct 16, 2018

@kozlovsky kozlovsky closed this in d4b0291 Oct 16, 2018

@kozlovsky

This comment has been minimized.

Copy link
Member

kozlovsky commented Oct 16, 2018

Thanks, should work now

@ichorid

This comment has been minimized.

Copy link
Author

ichorid commented Jan 15, 2019

Still have this problem, with the same code! Pony PIP 0.7.6, Python 2.7.15rc1

@ichorid

This comment has been minimized.

Copy link
Author

ichorid commented Jan 15, 2019

Traceback (most recent call last):
  File "./pony_buffers3.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
@andreymal

This comment has been minimized.

Copy link

andreymal commented Jan 15, 2019

It's not released yet, install pony from github

kozlovsky added a commit that referenced this issue Jan 17, 2019

PonyORM release 0.7.7 (2019-01-17)
# Major features

* Array type support for PostgreSQL and SQLite
* isinstance() support in queries
* Support of queries based on collections: select(x for x in y.items)

# Other features

* Support of Entity.select(**kwargs)
* Support of SKIP LOCKED option in 'SELECT ... FOR UPDATE'
* New function make_proxy(obj) to make cros-db_session proxy objects
* Specify ON DELETE CASCADE/SET NULL in foreign keys
* Support of LIMIT in `SELECT FROM (SELECT ...)` type of queries
* Support for negative JSON array indexes in SQLite

# Improvements

* Improved query prefetching: use fewer number of SQL queries
* Memory optimization: deduplication of values recieved from the database in the same session
* increase DBAPIProvider.max_params_count value

# Bugfixes

* #405: breaking change with cx_Oracle 7.0: DML RETURNING now returns a list
* #380: db_session should work with async functions
* #385: test fails with python3.6
* #386: release unlocked lock error in SQLite
* #390: TypeError: writable buffers are not hashable
* #398: add auto coversion of numpy numeric types
* #404: GAE local run detection
* Fix Flask compatibility: add support of LocalProxy object
* db_session(sql_debug=True) should log SQL commands also during db_session.__exit__()
* Fix duplicated table join in FROM clause
* Fix accessing global variables from hybrid methods and properties
* Fix m2m collection loading bug
* Fix composite index bug: stackoverflow.com/questions/53147694
* Fix MyEntity[obj.get_pk()] if pk is composite
* MySQL group_concat_max_len option set to max of 32bit platforms to avoid truncation
* Show all attribute options in show(Entity) call
* For nested db_session retry option should be ignored
* Fix py_json_unwrap
* Other minor fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment