Skip to content

Commit

Permalink
fix large integers in SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Dec 1, 2024
1 parent 7373a84 commit ed2874b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion piccolo/engine/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def convert_int_out(value: str) -> int:
"""
Make sure Integer values are actually of type int.
"""
return int(float(value))
return int(value)


@decode_to_string
Expand Down
30 changes: 30 additions & 0 deletions tests/columns/test_integer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from piccolo.columns.column_types import Integer
from piccolo.table import Table
from piccolo.testing.test_case import AsyncTableTest


class MyTable(Table):
integer = Integer()


class TestInteger(AsyncTableTest):
tables = [MyTable]

async def test_large_integer(self):
"""
Make sure large integers can be inserted and retrieved correctly.
There was a bug with this in SQLite:
https://github.com/piccolo-orm/piccolo/issues/1127
"""
integer = 625757527765811240

row = MyTable(integer=integer)
await row.save()

_row = MyTable.objects().first().run_sync()
assert _row is not None

self.assertEqual(_row.integer, integer)

0 comments on commit ed2874b

Please sign in to comment.