Skip to content
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

"Select" fails when PrimaryKey is Buffer object #355

Closed
ichorid opened this Issue Jun 23, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@ichorid
Copy link

ichorid commented Jun 23, 2018

When buffer is used as PrimaryKey, select always fails:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-24-08cbfe0fdb1f> in <module>()
----> 1 q[:]

/home/vader/.pyenv/versions/2.7.14/envs/tribler/lib/python2.7/site-packages/pony/orm/core.pyc in __getitem__(query, key)

/home/vader/.pyenv/versions/2.7.14/envs/tribler/lib/python2.7/site-packages/pony/utils/utils.pyc in cut_traceback(func, *args, **kwargs)
     75             if module_name.startswith('pony.utils') and tb.tb_frame.f_code.co_name == 'throw':
     76                 reraise(exc_type, exc, last_pony_tb)
---> 77             reraise(exc_type, exc, full_tb)
     78         finally:
     79             del exc, full_tb, tb, last_pony_tb

/home/vader/.pyenv/versions/2.7.14/envs/tribler/lib/python2.7/site-packages/pony/utils/utils.pyc in cut_traceback(func, *args, **kwargs)
     58         return func(*args, **kwargs)
     59 
---> 60     try: return func(*args, **kwargs)
     61     except AssertionError: raise
     62     except Exception:

/home/vader/.pyenv/versions/2.7.14/envs/tribler/lib/python2.7/site-packages/pony/orm/core.pyc in __getitem__(query, key)
   5692             stop = key.stop
   5693             if stop is None:
-> 5694                 if not start: return query._fetch()
   5695                 else: throw(TypeError, "Parameter 'stop' of slice object should be specified")
   5696         else: throw(TypeError, 'If you want apply index to query, convert it to list first')

/home/vader/.pyenv/versions/2.7.14/envs/tribler/lib/python2.7/site-packages/pony/orm/core.pyc in _fetch(query, range)
   5345                 entity = translator.expr_type
   5346                 result = entity._fetch_objects(cursor, attr_offsets, for_update=query._for_update,
-> 5347                                                used_attrs=translator.get_used_attrs())
   5348             elif len(translator.row_layout) == 1:
   5349                 func, slice_or_offset, src = translator.row_layout[0]

/home/vader/.pyenv/versions/2.7.14/envs/tribler/lib/python2.7/site-packages/pony/orm/core.pyc in _fetch_objects(entity, cursor, attr_offsets, max_fetch_count, for_update, used_attrs)
   3989             for row in rows:
   3990                 real_entity_subclass, pkval, avdict = entity._parse_row_(row, attr_offsets)
-> 3991                 obj = real_entity_subclass._get_from_identity_map_(pkval, 'loaded', for_update)
   3992                 if obj._status_ in del_statuses: continue
   3993                 obj._db_set_(avdict)

/home/vader/.pyenv/versions/2.7.14/envs/tribler/lib/python2.7/site-packages/pony/orm/core.pyc in _get_from_identity_map_(entity, pkval, status, for_update, undo_funcs, obj_to_init)
   4083         cache_index = cache.indexes[pk_attrs]
   4084         if pkval is None: obj = None
-> 4085         else: obj = cache_index.get(pkval)
   4086 
   4087         if obj is None: pass

TypeError: writable buffers are not hashable

Steps to reproduce:

from pony import orm

db = orm.Database()
class Bla(db.Entity):
    smt = orm.PrimaryKey(buffer, auto=False)
db.bind(provider='sqlite', filename=':memory:')
db.generate_mapping(create_tables=True)
a = Bla(smt=str(0x01)*20)
q = orm.select(p for p in Bla)[:]

@sashaaero sashaaero self-assigned this Jul 31, 2018

@sashaaero sashaaero added the bug label Jul 31, 2018

@sashaaero sashaaero added this to the 0.7.6 milestone Jul 31, 2018

@sashaaero

This comment has been minimized.

Copy link
Member

sashaaero commented Jul 31, 2018

Hello! Yes, this was a bug. SQLite in Python2 for some reason always returns read-write buffer and it's obviously unhashable. Fix will appear on GitHub soon.

@kozlovsky kozlovsky closed this in cfad342 Jul 31, 2018

kozlovsky added a commit that referenced this issue Aug 8, 2018

Pony ORM Release 0.7.6rc1 (2018-08-08)
# New features

* f-strings support in queries: select(f'{s.name} - {s.age}' for s in Student)
* #344: It is now possible to specify offset without limit: `query.limit(offset=10)`
* #371: Support of explicit casting of JSON expressions to `str`, `int` or `float`
* `@db.on_connect` decorator added

# Bugfixes

* Fix bulk delete bug introduced in 0.7.4
* #370 Fix memory leak introduced in 0.7.4
* Now exists() in query does not throw away condition in generator expression: `exists(s.gpa > 3 for s in Student)`
* #373: 0.7.4/0.7.5 breaks queries using the `in` operator to test membership of another query result
* #374: `auto=True` can be used with all PrimaryKey types, not only int
* #369: Make QueryResult looks like a list object again: add concatenation with lists, `.shuffle()` and `.to_list()` methods
* #355: Fix binary primary keys `PrimaryKey(buffer)` in Python2
* Interactive mode support for PyCharm console
* Fix wrong table aliases in complex queries
* Fix query optimization code for complex queries

kozlovsky added a commit that referenced this issue Aug 10, 2018

Pony ORM Release 0.7.6 (2018-08-10)
# Features since 0.7.5:

* f-strings support in queries: `select(f'{s.name} - {s.age}' for s in Student)`
* #344: It is now possible to specify offset without limit: `query.limit(offset=10)`
* #371: Support of explicit casting of JSON expressions to `str`, `int` or `float`
* `@db.on_connect` decorator added

# Bugfixes

* Fix bulk delete bug introduced in 0.7.4
* #370 Fix memory leak introduced in 0.7.4
* Now `exists()` in query does not throw away condition in generator expression: `exists(s.gpa > 3 for s in Student)`
* #373: 0.7.4/0.7.5 breaks queries using the `in` operator to test membership of another query result
* #374: `auto=True` can be used with all PrimaryKey types, not only `int`
* #369: Make QueryResult looks like a list object again: add concatenation with lists, `.shuffle()` and `.to_list()` methods
* #355: Fix binary primary keys `PrimaryKey(buffer)` in Python2
* Interactive mode support for PyCharm console
* Fix wrong table aliases in complex queries
* Fix query optimization code for complex queries
* Fix a bug with hybrid properties that use external functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.