simple_search_list_txn should return None, not 0. (#8187)

This commit is contained in:
Patrick Cloke 2020-08-27 12:07:13 -04:00 committed by GitHub
parent 5649b7f3d0
commit c9fa696ea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

1
changelog.d/8187.misc Normal file
View File

@ -0,0 +1 @@
Add type hints to `synapse.storage.database`.

View File

@ -28,7 +28,6 @@ from typing import (
Optional, Optional,
Tuple, Tuple,
TypeVar, TypeVar,
Union,
overload, overload,
) )
@ -1655,7 +1654,7 @@ class DatabasePool(object):
term: Optional[str], term: Optional[str],
col: str, col: str,
retcols: Iterable[str], retcols: Iterable[str],
) -> Union[List[Dict[str, Any]], int]: ) -> Optional[List[Dict[str, Any]]]:
"""Executes a SELECT query on the named table, which may return zero or """Executes a SELECT query on the named table, which may return zero or
more rows, returning the result as a list of dicts. more rows, returning the result as a list of dicts.
@ -1667,14 +1666,14 @@ class DatabasePool(object):
retcols: the names of the columns to return retcols: the names of the columns to return
Returns: Returns:
0 if no term is given, otherwise a list of dictionaries. None if no term is given, otherwise a list of dictionaries.
""" """
if term: if term:
sql = "SELECT %s FROM %s WHERE %s LIKE ?" % (", ".join(retcols), table, col) sql = "SELECT %s FROM %s WHERE %s LIKE ?" % (", ".join(retcols), table, col)
termvalues = ["%%" + term + "%%"] termvalues = ["%%" + term + "%%"]
txn.execute(sql, termvalues) txn.execute(sql, termvalues)
else: else:
return 0 return None
return cls.cursor_to_dict(txn) return cls.cursor_to_dict(txn)