Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Append % in python, rather than in query
Browse files Browse the repository at this point in the history
Synapse translates %'s under the hood for each database engine. Including them in the query string
instead of in the args can break things.
  • Loading branch information
anoadragon453 committed Feb 11, 2021
1 parent 892ed0f commit 94de710
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions synapse/storage/databases/main/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,17 +766,17 @@ async def search_user_dir(self, user_id, search_term, limit):
# The statement checks whether a given user's user ID contains a domain name
# that matches the local server
if isinstance(self.database_engine, PostgresEngine):
statement = "* (CASE WHEN user_id LIKE '%:' || ? THEN 2.0 ELSE 1.0 END)"
statement = "* (CASE WHEN user_id LIKE ? THEN 2.0 ELSE 1.0 END)"
elif isinstance(self.database_engine, Sqlite3Engine):
# Note that we need to include a comma at the end for valid SQL
statement = "user_id LIKE '%:' || ? DESC,"
statement = "user_id LIKE ? DESC,"
else:
# This should be unreachable.
raise Exception("Unrecognized database engine")
additional_ordering_statements.append(statement)

# Append the local server name as an argument to the final query
ordering_arguments += (self._server_name,)
ordering_arguments += ("%:" + self._server_name,)

if isinstance(self.database_engine, PostgresEngine):
full_query, exact_query, prefix_query = _parse_query_postgres(search_term)
Expand Down

0 comments on commit 94de710

Please sign in to comment.