# HG changeset patch # User Goffi # Date 1709993594 -3600 # Node ID 79a4870cfbdf78c1366a599609ac281ce08598fa # Parent dfccc90cacc61480288c33cc5e801ebb18171756 migration: fix migration when XEP-0373 or XEP-0384 can't be imported: Those plugins are using optional modules, and if their importation fails, there is probably no data to migrate either. diff -r dfccc90cacc6 -r 79a4870cfbdf libervia/backend/memory/migration/versions/fe3a02cb4bec_convert_legacypickle_columns_to_json.py --- a/libervia/backend/memory/migration/versions/fe3a02cb4bec_convert_legacypickle_columns_to_json.py Tue Mar 05 17:31:56 2024 +0100 +++ b/libervia/backend/memory/migration/versions/fe3a02cb4bec_convert_legacypickle_columns_to_json.py Sat Mar 09 15:13:14 2024 +0100 @@ -9,8 +9,22 @@ import sqlalchemy as sa import pickle import json -from libervia.backend.plugins.plugin_xep_0373 import PublicKeyMetadata -from libervia.backend.plugins.plugin_xep_0384 import TrustMessageCacheEntry +try: + from libervia.backend.plugins.plugin_xep_0373 import PublicKeyMetadata +except Exception: + PublicKeyMetadata = None + print( + "Warning: Can't import XEP-0373, its data won't be updated. It's probably not " + "used on this installation." + ) +try: + from libervia.backend.plugins.plugin_xep_0384 import TrustMessageCacheEntry +except Exception: + TrustMessageCacheEntry = None + print( + "Warning: Can't import XEP-0384, its data won't be updated. It's probably not " + "used on this installation." + ) # revision identifiers, used by Alembic. revision = "fe3a02cb4bec" @@ -35,7 +49,8 @@ encoding="utf-8", ) if ( - table == "private_ind_bin" + PublicKeyMetadata is not None + and table == "private_ind_bin" and primary_keys[0] == "XEP-0373" and not primary_keys[1].startswith("/trust") and isinstance(deserialized, set) @@ -48,7 +63,8 @@ deserialized = [pkm.to_dict() for pkm in deserialized] elif ( - table == "private_ind_bin" + TrustMessageCacheEntry is not None + and table == "private_ind_bin" and primary_keys[0] == "XEP-0384/TM" and primary_keys[1] == "cache" ): @@ -113,7 +129,8 @@ # Check for the specific table and primary key conditions that require special # handling if ( - table == "private_ind_bin" + PublicKeyMetadata is not None + and table == "private_ind_bin" and primary_keys[0] == "XEP-0373" and not primary_keys[1].startswith("/trust") ): @@ -121,7 +138,8 @@ if isinstance(deserialized, list): deserialized = {PublicKeyMetadata.from_dict(d) for d in deserialized} elif ( - table == "private_ind_bin" + TrustMessageCacheEntry is not None + and table == "private_ind_bin" and primary_keys[0] == "XEP-0384/TM" and primary_keys[1] == "cache" ):