From 74587f420c8262b39ab3613e7db2c5a9dfa4487d Mon Sep 17 00:00:00 2001 From: Elia Migliore Date: Tue, 2 Jul 2024 12:43:59 +0200 Subject: [PATCH] fix: remove the raise Invalid version when instantiating a version 0. This is required due to back compatibility, in the past was possible to create schema with version 0, we should deny creating new versions starting from 0 but not raising an issue if this is done during the load of the previous schema --- karapace/typing.py | 2 +- tests/unit/test_schema_models.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/karapace/typing.py b/karapace/typing.py index 02b14d4c1..4daf4739e 100644 --- a/karapace/typing.py +++ b/karapace/typing.py @@ -69,7 +69,7 @@ class Version: def __init__(self, version: int) -> None: if not isinstance(version, int): raise InvalidVersion(f"Invalid version {version}") - if (version < Version.MINUS_1_VERSION_TAG) or (version == 0): + if version < Version.MINUS_1_VERSION_TAG: raise InvalidVersion(f"Invalid version {version}") self._value = version diff --git a/tests/unit/test_schema_models.py b/tests/unit/test_schema_models.py index 9b27d27a0..392738335 100644 --- a/tests/unit/test_schema_models.py +++ b/tests/unit/test_schema_models.py @@ -45,6 +45,10 @@ def test_invalid_version(self, invalid_version: VersionTag): def test_is_latest(self, version: Version, is_latest: bool): assert version.is_latest is is_latest + def version_0_its_constructable(self) -> None: + version_0 = Version(0) + assert version_0.value == 0 + def test_text_formating(self, version: Version): assert f"{version}" == "1" assert f"{version!r}" == "Version(1)" @@ -159,7 +163,11 @@ def test_factory_V(self, tag: VersionTag, resolved: int): def test_validate(self, tag: VersionTag): Versioner.validate_tag(tag=tag) - @pytest.mark.parametrize("tag", ["invalid_version", 0, -20, "0"]) + @pytest.mark.parametrize("tag", ["invalid_version", "0", -20]) def test_validate_invalid(self, tag: VersionTag): + """ + Tagger should still keep invalid version 0, we are only backwards compatible, and we should + avoid generating 0 as a new tag for any schema. + """ with pytest.raises(InvalidVersion): Versioner.validate_tag(tag=tag)