Foreign Key Query Error In Case Of Custom Uint64 Field Which Was Used As A Primary Key
I needed uint64 field as primary key field for my database, expectedly other models used foreign key to point to this model. Resulting code was something like this:
from peewee import * db = SqliteDatabase('test.db') class UInt64(Field): db_field = 'bigint' def db_value(self, value): return value - (1<<63) def python_value(self, value): return value + (1<<63) class Foo(Model): id = UInt64(primary_key = True) class Meta: database = db class Bar(Model): id = UInt64(primary_key = True) foo = ForeignKeyField(Foo, related_name='bars')
This code works properly for all requests used by me expect one:
>>> f = Foo.create(id=10000) >>> Bar.create(id=123, foo=f) <ptest.Bar object at 0x7f2fde7f7e10> >>> b = Bar.get() >>> b.id 123 >>> b.foo Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 1151, in __get__ return self.get_object_or_id(instance) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 1142, in get_object_or_id obj = self.rel_model.get(self.field.to_field == rel_id) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 4403, in get return sq.get() File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2812, in get return clone.execute().next() File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2859, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2555, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) OverflowError: Python int too large to convert to SQLite INTEGER
It seems that somewhere conversion between python value and db value was not done properly. Looks like a bug to me.
Any ideas how it can be fixed without directly saving foo id in Bar as UInt64 instead of use of ForeignKeyField?
It was a bug in peewee, which is now fixed: https://github.com/coleifer/peewee/issues/791
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module