From e64d9a95d82fffd5608ddbf9a9536c6ada4a6caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Mas=C5=82owski?= Date: Wed, 13 Aug 2025 10:34:14 +0000 Subject: [PATCH 1/2] Exclude elements from the schemas module when checking for revisions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During revision checking, we dynamically replace the type of the "operations" field with a more general type. This way, the "OperationRepresentationUnion" classes won’t appear in schema_json, and therefore won’t be considered in the revision verification. --- clive/__private/storage/migrations/base.py | 14 +++++++++++++- clive/__private/storage/migrations/v0.py | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/clive/__private/storage/migrations/base.py b/clive/__private/storage/migrations/base.py index 525897f1b5..d02846af80 100644 --- a/clive/__private/storage/migrations/base.py +++ b/clive/__private/storage/migrations/base.py @@ -82,7 +82,19 @@ class ProfileStorageBase(PreconfiguredBaseModel): @classmethod def get_this_revision(cls) -> Revision: assert cls is not ProfileStorageBase, "This method should be called on subclass." - return sha256(cls._get_revision_seed().encode()).hexdigest()[:8] + return sha256(cls.get_model_for_schema_json()._get_revision_seed().encode()).hexdigest()[:8] + + @classmethod + def get_model_for_schema_json(cls) -> type[ProfileStorageBase]: + schema = cls._get_model_for_schema_json() + cls._REGISTERED_MODELS.remove( + schema + ) # Remove unnecessary duplication of the model schema due to __init_subclass__ being called by defstruct + return schema + + @classmethod + def _get_model_for_schema_json(cls) -> type[ProfileStorageBase]: + raise NotImplementedError("This method should be overridden in subclasses to provide a model for schema JSON.") @classmethod def get_this_version(cls) -> Version: diff --git a/clive/__private/storage/migrations/v0.py b/clive/__private/storage/migrations/v0.py index 46e0ce3386..e6a958436f 100644 --- a/clive/__private/storage/migrations/v0.py +++ b/clive/__private/storage/migrations/v0.py @@ -2,7 +2,9 @@ from __future__ import annotations from collections.abc import Sequence # noqa: TC003 from pathlib import Path # noqa: TC003 -from typing import Any, Self +from typing import Any, Self, cast + +import msgspec from clive.__private.core.alarms.specific_alarms import ( ChangingRecoveryAccountInProgress, @@ -102,6 +104,23 @@ class ProfileStorageModel(ProfileStorageBase, kw_only=True): def upgrade(cls, old: ProfileStorageBase) -> Self: raise NotImplementedError("Upgrade is not not possible for first revision.") + @classmethod + def _get_model_for_schema_json(cls) -> type[ProfileStorageBase]: + transaction_core_storage_model = msgspec.defstruct( + "TransactionCoreStorageModel", [("operations", list[Any])], bases=(cls.TransactionCoreStorageModel,) + ) + + transaction_storage_model = msgspec.defstruct( + "TransactionStorageModel", + [("transaction_core", transaction_core_storage_model)], + bases=(cls.TransactionStorageModel,), + ) + + return cast( + "type[ProfileStorageBase]", + msgspec.defstruct("ProfileStorageModel", [("transaction", transaction_storage_model)], bases=(cls,)), + ) + @classmethod def _preprocess_data(cls, data: dict[str, Any]) -> dict[str, Any]: cls._ensure_non_negative_tapos_fields(data) -- GitLab From 17d9d57187c5ed33bda13832597c292c0f65a546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Mas=C5=82owski?= Date: Wed, 13 Aug 2025 10:25:02 +0000 Subject: [PATCH 2/2] Update revisions in test_storage_revision --- tests/unit/storage/test_storage_revision.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/storage/test_storage_revision.py b/tests/unit/storage/test_storage_revision.py index 28220775cd..7e008a4c5d 100644 --- a/tests/unit/storage/test_storage_revision.py +++ b/tests/unit/storage/test_storage_revision.py @@ -5,7 +5,7 @@ from typing import Final from clive.__private.storage import ProfileStorageModel from clive.__private.storage.storage_history import StorageHistory -REVISIONS: Final[list[str]] = ["0313f118", "aaae09eb", "b52dcff7"] +REVISIONS: Final[list[str]] = ["9a0f921d", "8ea8b44e", "5c607c43"] LATEST_REVISION: Final[str] = REVISIONS[-1] -- GitLab