misc: don't look for cards with an id over postgresql limit (#47767)

This commit is contained in:
Frédéric Péters 2020-10-18 14:51:55 +02:00
parent 4dd7bc4aaa
commit 16a147d537
2 changed files with 17 additions and 0 deletions

View File

@ -108,3 +108,16 @@ def test_template_access(pub):
tmpl = Template('{{cards|objects:"foo"|filter_by:"foo"|filter_value:"blah"|count}}')
assert tmpl.render(context) == '10'
def test_data_source_access_invalid_id(pub):
CardDef.wipe()
carddef = CardDef()
carddef.name = 'foo'
carddef.fields = [
StringField(id='1', label='Test', type='string', varname='foo'),
]
carddef.store()
carddef.data_class().wipe()
assert CardDef.get_data_source_items('carddef:foo', get_by_id='424508729041982') == []

View File

@ -193,6 +193,10 @@ class CardDef(FormDef):
if query:
criterias.append(ILike('digest', query))
if get_by_id:
if int(get_by_id) >= 2**31:
# out of range for postgresql integer type; would raise
# DataError.
return []
criterias.append(Equal('id', get_by_id))
if get_by_text:
criterias.append(Equal('digest', get_by_text))