Order of operations matters
This commit is contained in:
parent
0db71275f6
commit
973e9a40fe
1 changed files with 11 additions and 3 deletions
|
|
@ -47,8 +47,16 @@ log = logging.getLogger("keycloak_bot")
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class PickleCryptoStore(MemoryCryptoStore):
|
class PickleCryptoStore(MemoryCryptoStore):
|
||||||
def __init__(self, filepath: str, account_id: str = "bot", pickle_key: str = ""):
|
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.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()
|
self.load()
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
|
@ -56,7 +64,7 @@ class PickleCryptoStore(MemoryCryptoStore):
|
||||||
try:
|
try:
|
||||||
with open(self.filepath, "rb") as f:
|
with open(self.filepath, "rb") as f:
|
||||||
data = pickle.load(f)
|
data = pickle.load(f)
|
||||||
self.accounts = data.get("accounts", {})
|
self.account = data.get("account", None)
|
||||||
self.sessions = data.get("sessions", {})
|
self.sessions = data.get("sessions", {})
|
||||||
self.inbound_group_sessions = data.get("inbound_group_sessions", {})
|
self.inbound_group_sessions = data.get("inbound_group_sessions", {})
|
||||||
self.outbound_group_sessions = data.get("outbound_group_sessions", {})
|
self.outbound_group_sessions = data.get("outbound_group_sessions", {})
|
||||||
|
|
@ -69,7 +77,7 @@ class PickleCryptoStore(MemoryCryptoStore):
|
||||||
def save(self):
|
def save(self):
|
||||||
try:
|
try:
|
||||||
data = {
|
data = {
|
||||||
"accounts": self.accounts,
|
"account": self.account,
|
||||||
"sessions": self.sessions,
|
"sessions": self.sessions,
|
||||||
"inbound_group_sessions": self.inbound_group_sessions,
|
"inbound_group_sessions": self.inbound_group_sessions,
|
||||||
"outbound_group_sessions": self.outbound_group_sessions,
|
"outbound_group_sessions": self.outbound_group_sessions,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue