mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 11:09:23 -05:00
Handle the fact that in sqlite binary data might be stored as unicode or bytes
This commit is contained in:
parent
ce797ad373
commit
7ed2ec3061
@ -812,6 +812,9 @@ class SQLBaseStore(object):
|
|||||||
|
|
||||||
internal_metadata, js, redacted, rejected_reason = res
|
internal_metadata, js, redacted, rejected_reason = res
|
||||||
|
|
||||||
|
internal_metadata = self.database_engine.load_unicode(internal_metadata)
|
||||||
|
js = self.database_engine.load_unicode(js)
|
||||||
|
|
||||||
start_time = update_counter("select_event", start_time)
|
start_time = update_counter("select_event", start_time)
|
||||||
|
|
||||||
result = self._get_event_from_row_txn(
|
result = self._get_event_from_row_txn(
|
||||||
@ -839,11 +842,11 @@ class SQLBaseStore(object):
|
|||||||
return curr_time
|
return curr_time
|
||||||
|
|
||||||
logger.debug("Got js: %r", js)
|
logger.debug("Got js: %r", js)
|
||||||
d = json.loads(str(js).decode("utf8"))
|
d = json.loads(js)
|
||||||
start_time = update_counter("decode_json", start_time)
|
start_time = update_counter("decode_json", start_time)
|
||||||
|
|
||||||
logger.debug("Got internal_metadata: %r", internal_metadata)
|
logger.debug("Got internal_metadata: %r", internal_metadata)
|
||||||
internal_metadata = json.loads(str(internal_metadata).decode("utf8"))
|
internal_metadata = json.loads(internal_metadata)
|
||||||
start_time = update_counter("decode_internal", start_time)
|
start_time = update_counter("decode_internal", start_time)
|
||||||
|
|
||||||
ev = FrozenEvent(
|
ev = FrozenEvent(
|
||||||
|
@ -27,7 +27,7 @@ class MariaEngine(object):
|
|||||||
|
|
||||||
def encode_parameter(self, param):
|
def encode_parameter(self, param):
|
||||||
if isinstance(param, types.BufferType):
|
if isinstance(param, types.BufferType):
|
||||||
return str(param)
|
return bytes(param)
|
||||||
return param
|
return param
|
||||||
|
|
||||||
def on_new_connection(self, db_conn):
|
def on_new_connection(self, db_conn):
|
||||||
@ -45,3 +45,6 @@ class MariaEngine(object):
|
|||||||
if isinstance(error, self.module.DatabaseError):
|
if isinstance(error, self.module.DatabaseError):
|
||||||
return error.sqlstate == "40001" and error.errno == 1213
|
return error.sqlstate == "40001" and error.errno == 1213
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def load_unicode(self, v):
|
||||||
|
return bytes(v).decode("UTF8")
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
from synapse.storage import prepare_database, prepare_sqlite3_database
|
from synapse.storage import prepare_database, prepare_sqlite3_database
|
||||||
|
|
||||||
|
import types
|
||||||
|
|
||||||
|
|
||||||
class Sqlite3Engine(object):
|
class Sqlite3Engine(object):
|
||||||
def __init__(self, database_module):
|
def __init__(self, database_module):
|
||||||
@ -35,3 +37,8 @@ class Sqlite3Engine(object):
|
|||||||
|
|
||||||
def is_deadlock(self, error):
|
def is_deadlock(self, error):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def load_unicode(self, v):
|
||||||
|
if isinstance(v, types.UnicodeType):
|
||||||
|
return v
|
||||||
|
return bytes(v).decode("UTF8")
|
||||||
|
@ -36,7 +36,7 @@ class ProfileStore(SQLBaseStore):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if name:
|
if name:
|
||||||
name = name.decode("utf8")
|
name = self.database_engine.load_unicode(name)
|
||||||
|
|
||||||
defer.returnValue(name)
|
defer.returnValue(name)
|
||||||
|
|
||||||
|
@ -99,7 +99,9 @@ class RegistrationStore(SQLBaseStore):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if user_info:
|
if user_info:
|
||||||
user_info["password_hash"] = user_info["password_hash"].decode("utf8")
|
user_info["password_hash"] = self.database_engine.load_unicode(
|
||||||
|
user_info["password_hash"]
|
||||||
|
)
|
||||||
|
|
||||||
defer.returnValue(user_info)
|
defer.returnValue(user_info)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user