sql: avoid asking postgresql for out-of-range id (#73963)

This commit is contained in:
Frédéric Péters 2023-01-30 17:45:58 +01:00 committed by Gitea
parent 1d64138735
commit d4ad7c4d75
2 changed files with 4 additions and 1 deletions

View File

@ -112,6 +112,7 @@ def test_sql_get(formdef):
assert data_class.get('foo', ignore_errors=True) is None
assert data_class.get(True, ignore_errors=True) is None
assert data_class.get(False, ignore_errors=True) is None
assert data_class.get(2**32, ignore_errors=True) is None
def test_sql_store_channel(formdef):

View File

@ -2888,7 +2888,9 @@ class SqlDataMixin(SqlMixin):
@guard_postgres
def get(cls, id, ignore_errors=False, ignore_migration=False):
try:
int(str(id))
if not (0 < int(str(id)) < 2**31):
# avoid NumericValueOutOfRange
raise TypeError()
except (TypeError, ValueError):
if ignore_errors:
return None