Check object_cache is None before pulling row id.

This commit is contained in:
voussoir 2023-07-22 17:16:56 -07:00
parent 019bba23f2
commit eb4e381022

View file

@ -651,15 +651,16 @@ class DatabaseWithCaching(Database, metaclass=abc.ABCMeta):
object_table = object_class.table object_table = object_class.table
object_cache = self.caches.get(object_class, None) object_cache = self.caches.get(object_class, None)
if object_cache is None:
log.loud('The %s table is not cached. Returning new instance.', object_class.table)
return object_class(self, db_row)
if isinstance(db_row, (dict, sqlite3.Row)): if isinstance(db_row, (dict, sqlite3.Row)):
object_id = db_row['id'] object_id = db_row['id']
else: else:
object_index = self.COLUMN_INDEX[object_table] object_index = self.COLUMN_INDEX[object_table]
object_id = db_row[object_index['id']] object_id = db_row[object_index['id']]
if object_cache is None:
return object_class(self, db_row)
try: try:
instance = object_cache[object_id] instance = object_cache[object_id]
except KeyError: except KeyError: