From a519a21f04cfa0cc783bd37ffd5ee90ce1078f2e Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Tue, 1 Mar 2022 18:43:26 -0500 Subject: [PATCH] Remove floating point from our understanding of SQL Arguably we never really understood it anyway. --- src/_zkapauthorizer/tests/sql.py | 8 +++++++- src/_zkapauthorizer/tests/strategies.py | 15 +-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/_zkapauthorizer/tests/sql.py b/src/_zkapauthorizer/tests/sql.py index 13b5a26..0745de8 100644 --- a/src/_zkapauthorizer/tests/sql.py +++ b/src/_zkapauthorizer/tests/sql.py @@ -17,10 +17,16 @@ class StorageAffinity(Enum): column. """ + # Notably, this excludes REAL because I don't know how to get floating + # point values to round-trip through the snapshot/recover implementation + # on Windows. ZKAPAuthorizer itself doesn't need REAL / floating point + # values so this limitation doesn't bother us in practice (ideally + # something somewhere would enforce this so no one accidentally starts + # using floating point values thinking the system will handle them). + INT = auto() TEXT = auto() BLOB = auto() - REAL = auto() NUMERIC = auto() diff --git a/src/_zkapauthorizer/tests/strategies.py b/src/_zkapauthorizer/tests/strategies.py index 5b447a5..397c901 100644 --- a/src/_zkapauthorizer/tests/strategies.py +++ b/src/_zkapauthorizer/tests/strategies.py @@ -1224,18 +1224,6 @@ def tables() -> SearchStrategy[Table]: # https://www.sqlite.org/floatingpoint.html#how_sqlite_stores_numbers _sql_integer = integers(min_value=-(2 ** 63) + 1, max_value=2 ** 63 - 1) -# SQLite3 can do infinity and NaN but I don't know how to get them through the -# Python interface. SQLite3 can do 64 bit floats but it only guarantees 15 -# digits of precision (maybe only for its base 10 string representations?) -# which causes values requiring greater precision to fail to round-trip. The -# SQLite3 docs are quite clear about what one should expect from floating -# point values, anyway: -# -# Floating point values are approximate. -# -# https://www.sqlite.org/floatingpoint.html -_sql_floats = floats(allow_infinity=False, allow_nan=False, width=32) - # Exclude surrogates because SQLite3 uses UTF-8 and we don't need them. Also # they have to come in correctly formed pairs to be legal anyway and it's # inconvenient to do that with text. @@ -1261,8 +1249,7 @@ _storage_affinity_strategies = { StorageAffinity.INT: _sql_integer, StorageAffinity.TEXT: _sql_text, StorageAffinity.BLOB: binary(), - StorageAffinity.REAL: _sql_floats, - StorageAffinity.NUMERIC: one_of(_sql_integer, _sql_floats), + StorageAffinity.NUMERIC: _sql_integer, } -- GitLab