From 973e9a40fe0f0e95b0cfe4290a9b0c9cee2d9dad Mon Sep 17 00:00:00 2001 From: Astra Logical Date: Thu, 23 Jul 2026 14:15:41 -0400 Subject: [PATCH] Order of operations matters --- matrix_keycloak_bot.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/matrix_keycloak_bot.py b/matrix_keycloak_bot.py index b809bc3..5c5db66 100644 --- a/matrix_keycloak_bot.py +++ b/matrix_keycloak_bot.py @@ -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,