Order of operations matters

This commit is contained in:
Astra Logical 2026-07-23 14:15:41 -04:00
parent 0db71275f6
commit 973e9a40fe

View file

@ -47,8 +47,16 @@ log = logging.getLogger("keycloak_bot")
# ------------------------------------------------------------------------------
class PickleCryptoStore(MemoryCryptoStore):
def __init__(self, filepath: str, account_id: str = "bot", pickle_key: str = ""):
super().__init__(account_id=account_id, pickle_key=pickle_key)
# Pre-initialize all attributes so save() never hits an AttributeError
self.filepath = filepath
self.account = None
self.sessions = {}
self.inbound_group_sessions = {}
self.outbound_group_sessions = {}
self.devices = {}
self.cross_signing_keys = {}
super().__init__(account_id=account_id, pickle_key=pickle_key)
self.load()
def load(self):
@ -56,7 +64,7 @@ class PickleCryptoStore(MemoryCryptoStore):
try:
with open(self.filepath, "rb") as f:
data = pickle.load(f)
self.accounts = data.get("accounts", {})
self.account = data.get("account", None)
self.sessions = data.get("sessions", {})
self.inbound_group_sessions = data.get("inbound_group_sessions", {})
self.outbound_group_sessions = data.get("outbound_group_sessions", {})
@ -69,7 +77,7 @@ class PickleCryptoStore(MemoryCryptoStore):
def save(self):
try:
data = {
"accounts": self.accounts,
"account": self.account,
"sessions": self.sessions,
"inbound_group_sessions": self.inbound_group_sessions,
"outbound_group_sessions": self.outbound_group_sessions,