0001-sql-check-id-parameter-passed-to-.get-method-42827.patch
tests/test_sql.py | ||
---|---|---|
128 | 128 |
data_class = formdef.data_class(mode='sql') |
129 | 129 |
with pytest.raises(KeyError): |
130 | 130 |
data_class.get(123456) |
131 |
with pytest.raises(KeyError): |
|
132 |
data_class.get('xxx') |
|
131 | 133 | |
132 | 134 | |
133 | 135 |
@postgresql |
134 | 136 |
def test_sql_get_missing_ignore_errors(): |
135 | 137 |
data_class = formdef.data_class(mode='sql') |
136 | 138 |
assert data_class.get(123456, ignore_errors=True) is None |
139 |
assert data_class.get('xxx', ignore_errors=True) is None |
|
140 |
assert data_class.get(None, ignore_errors=True) is None |
|
137 | 141 | |
138 | 142 | |
139 | 143 |
def check_sql_field(no, value): |
wcs/sql.py | ||
---|---|---|
1021 | 1021 | |
1022 | 1022 |
class SqlMixin(object): |
1023 | 1023 |
_table_name = None |
1024 |
_numerical_id = True |
|
1024 | 1025 | |
1025 | 1026 |
@classmethod |
1026 | 1027 |
@guard_postgres |
... | ... | |
1095 | 1096 |
@classmethod |
1096 | 1097 |
@guard_postgres |
1097 | 1098 |
def get(cls, id, ignore_errors=False, ignore_migration=False): |
1098 |
if id is None: |
|
1099 |
if ignore_errors: |
|
1100 |
return None |
|
1101 |
else: |
|
1102 |
raise KeyError() |
|
1099 |
if cls._numerical_id or id is None: |
|
1100 |
try: |
|
1101 |
int(id) |
|
1102 |
except (TypeError, ValueError): |
|
1103 |
if ignore_errors and id is None: |
|
1104 |
return None |
|
1105 |
else: |
|
1106 |
raise KeyError() |
|
1103 | 1107 |
conn, cur = get_connection_and_cursor() |
1104 | 1108 | |
1105 | 1109 |
sql_statement = '''SELECT %s |
... | ... | |
1658 | 1662 |
@classmethod |
1659 | 1663 |
@guard_postgres |
1660 | 1664 |
def get(cls, id, ignore_errors=False, ignore_migration=False): |
1661 |
if id is None: |
|
1665 |
try: |
|
1666 |
int(id) |
|
1667 |
except (TypeError, ValueError): |
|
1662 | 1668 |
if ignore_errors: |
1663 | 1669 |
return None |
1664 | 1670 |
else: |
1665 | 1671 |
raise KeyError() |
1666 |
else: |
|
1667 |
try: |
|
1668 |
int(id) |
|
1669 |
except ValueError: |
|
1670 |
raise KeyError() |
|
1671 | 1672 |
conn, cur = get_connection_and_cursor() |
1672 | 1673 | |
1673 | 1674 |
fields = cls.get_data_fields() |
... | ... | |
1993 | 1994 |
('id', 'varchar'), |
1994 | 1995 |
('session_data', 'bytea'), |
1995 | 1996 |
] |
1997 |
_numerical_id = False |
|
1996 | 1998 | |
1997 | 1999 |
@classmethod |
1998 | 2000 |
@guard_postgres |
1999 |
- |