From ed2874bb5fbaa2274d2059032602e36e9230707e Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Sun, 1 Dec 2024 12:30:48 +0000 Subject: [PATCH] fix large integers in SQLite --- piccolo/engine/sqlite.py | 2 +- tests/columns/test_integer.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/columns/test_integer.py diff --git a/piccolo/engine/sqlite.py b/piccolo/engine/sqlite.py index 3f7649d76..3c36e5705 100644 --- a/piccolo/engine/sqlite.py +++ b/piccolo/engine/sqlite.py @@ -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 diff --git a/tests/columns/test_integer.py b/tests/columns/test_integer.py new file mode 100644 index 000000000..b5ec0a591 --- /dev/null +++ b/tests/columns/test_integer.py @@ -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)