From db4491b5fc775243ca50e1b1d708ed93c62d707e Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Thu, 29 Oct 2026 10:00:49 +0100 Subject: [PATCH] feat: version-stamp the Zimbra profile The zimbra profile was measured against the 2017 zcs-foss docker image (8.8). A Zimbra 10.1.21 server answers a PUT of a taken UID with 412 and the precondition rather than 403/409, so it failed testCheckCompatibility. No Zimbra 10 docker image exists, so the profile is split like bedework's; the old name still resolves, to zimbra_8_8. Named in a config it gives a FutureWarning, as DeprecationWarning is hidden by Python's default filters; accessed as compatibility_hints.zimbra in code it gives a DeprecationWarning. For the same reason the deprecated config keys testing_allowed and priority now give a FutureWarning instead of a DeprecationWarning. Prompt: work zimbra is Zimbra 10.1.21_GA_4899 (build 20260916050914) - it's quite normal for zimbra to add regressions in their caldav support in their "upgrades". Can we get the zimbra docker container updated? If not, then we should have versioned profiles like with bedework Followup-Prompt: go for the small fix. [rename zimbra to zimbra_8_8 with a deprecated alias, add zimbra_10_1] Prompts (comments made inline in the document while reviewing it): > (on whether to split the config-key warning change into its own commit) don't bother the split, make the message clear Assisted-By: Claude Opus 5.5 Reviewed-by: Tobias Brox --- caldav/compatibility_hints.py | 29 ++++++++++++- caldav/config.py | 26 +++++++++++- caldav/testing/docker.py | 2 +- .../+config-deprecations-visible.changed.md | 1 + .../+zimbra-versioned-profiles.deprecated.md | 1 + pyproject.toml | 3 +- tests/docker-test-servers/zimbra/README.md | 1 + tests/test_async_integration.py | 10 +---- tests/test_caldav_unit.py | 21 +++++++--- tests/test_compatibility_hints.py | 41 ++++++++++++++----- tests/test_uid_lookup_fallback.py | 4 +- 11 files changed, 110 insertions(+), 29 deletions(-) create mode 100644 changes/+config-deprecations-visible.changed.md create mode 100644 changes/+zimbra-versioned-profiles.deprecated.md diff --git a/caldav/compatibility_hints.py b/caldav/compatibility_hints.py index c36ae10df..007eb49d6 100644 --- a/caldav/compatibility_hints.py +++ b/caldav/compatibility_hints.py @@ -1771,8 +1771,10 @@ def compare(self, observed): }, } -## Zimbra is not very good at it's caldav support -zimbra = { +## Zimbra is not very good at it's caldav support. Measured against the +## zimbra/zcs-foss:latest docker image (Zimbra 8.8, built 2017); upgrades +## have been known to bring regressions, hence the version-stamped name. +zimbra_8_8 = { ## Measured with caldav-server-tester, 2026-10-27: the UID filter works although search.text does not. 'search.text.uid': {'support': 'full'}, ## Measured with caldav-server-tester, 2026-10-19. @@ -1899,6 +1901,29 @@ def compare(self, observed): "scheduling.auto-schedule": {"support": "unsupported"}, } +## Zimbra 10.1.21, measured with caldav-server-tester 2026-10-29 against an +## external server; there is no docker image of Zimbra 10. Only the differences found +## so far - everything else is assumed to be as in 8.8. +zimbra_10_1 = zimbra_8_8 | { + "save.no-uid-conflict": {"support": "quirk", "status": 412, "precondition": True, "behaviour": "refused with 412 and the precondition"}, + "save.no-uid-conflict.href-given": {"support": "full"}, +} + +def __getattr__(name: str) -> Any: + """Resolve a renamed profile, such as ``zimbra``, with a DeprecationWarning.""" + from caldav.config import DEPRECATED_FEATURE_PROFILES + + if name in DEPRECATED_FEATURE_PROFILES: + new_name, reason = DEPRECATED_FEATURE_PROFILES[name] + warnings.warn( + f"compatibility_hints.{name} has been renamed to {new_name} - {reason}", + DeprecationWarning, + stacklevel=2, + ) + return globals()[new_name] + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + + ## Measured against the `ioggstream/bedework:latest` docker image, which is ## a quickstart-3.10.3 tree on openjdk-8 and was built 2018-11-05 - the image ## cannot even be rebuilt, as the quickstart zip its Dockerfile fetches from diff --git a/caldav/config.py b/caldav/config.py index 4735a82de..18af4eb4a 100644 --- a/caldav/config.py +++ b/caldav/config.py @@ -85,6 +85,19 @@ def read_config(fn, interactive_error=False): ), } +## Profiles that have been renamed, but whose old name still resolves to the +## profile it always described. Named in a config, it gives a FutureWarning - +## a DeprecationWarning raised here would be hidden by Python's default +## filters, so the user would never learn to update the config. Accessed as +## an attribute of compatibility_hints, it gives a DeprecationWarning. +DEPRECATED_FEATURE_PROFILES = { + "zimbra": ( + "zimbra_8_8", + "the profile was measured against a Zimbra 8.8 docker image; use " + "zimbra_10_1 for a current Zimbra", + ), +} + def _lookup_feature_profile(name): """Look up a named profile in compatibility_hints. @@ -102,6 +115,15 @@ def _lookup_feature_profile(name): f"The compatibility profile '{name}' has been renamed to " f"'{new_name}' - {reason}. Update your configuration." ) + if name in DEPRECATED_FEATURE_PROFILES: + new_name, reason = DEPRECATED_FEATURE_PROFILES[name] + warnings.warn( + f"The compatibility profile '{name}' has been renamed to " + f"'{new_name}' - {reason}. Update your configuration.", + FutureWarning, + stacklevel=2, + ) + name = new_name try: return copy.deepcopy(getattr(caldav.compatibility_hints, name)) except AttributeError: @@ -175,7 +197,9 @@ def get_test_setting(section_data: dict[str, Any], key: str, default: Any = None if old_key and old_key in section_data: warnings.warn( f"The config key '{old_key}' is deprecated, use '{key}' instead", - DeprecationWarning, + ## Not DeprecationWarning: that would be hidden by default, and + ## the one to act on it is whoever edits the config file + FutureWarning, stacklevel=2, ) return section_data[old_key] diff --git a/caldav/testing/docker.py b/caldav/testing/docker.py index c508e5f6d..f31f55e77 100644 --- a/caldav/testing/docker.py +++ b/caldav/testing/docker.py @@ -438,7 +438,7 @@ def __init__(self, config: dict[str, Any] | None = None) -> None: config.setdefault("password", os.environ.get("ZIMBRA_PASSWORD", "testpass")) config.setdefault("ssl_verify_cert", False) if "features" not in config: - config["features"] = compatibility_hints.zimbra.copy() + config["features"] = compatibility_hints.zimbra_8_8.copy() # testuser/testuser2/testuser3 are created by start.sh for scheduling tests if "scheduling_users" not in config: domain = os.environ.get("ZIMBRA_DOMAIN", "zimbra.io") diff --git a/changes/+config-deprecations-visible.changed.md b/changes/+config-deprecations-visible.changed.md new file mode 100644 index 000000000..05869e64e --- /dev/null +++ b/changes/+config-deprecations-visible.changed.md @@ -0,0 +1 @@ +The deprecated config keys `testing_allowed` and `priority` now give a FutureWarning instead of a DeprecationWarning, which Python hides by default, so whoever edits the config file actually gets to see it. diff --git a/changes/+zimbra-versioned-profiles.deprecated.md b/changes/+zimbra-versioned-profiles.deprecated.md new file mode 100644 index 000000000..864278e8b --- /dev/null +++ b/changes/+zimbra-versioned-profiles.deprecated.md @@ -0,0 +1 @@ +The `zimbra` compatibility profile is renamed `zimbra_8_8`, as it was measured against a Zimbra 8.8 docker image, and `zimbra_10_1` is added: Zimbra 10.1 refuses a PUT of a UID the calendar already holds with 412 rather than 403 or 409. The old name still works, as `zimbra_8_8`: `features: zimbra` or `base: zimbra` in a config gives a FutureWarning, and `compatibility_hints.zimbra` in code a DeprecationWarning. diff --git a/pyproject.toml b/pyproject.toml index a8c55de5a..436571663 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -198,7 +198,8 @@ filterwarnings = [ "ignore:You need to install the `build` package:UserWarning", # An old key in the developer's own config file should not break the test run - "default:The config key '.*' is deprecated:DeprecationWarning", + "default:The config key '.*' is deprecated:FutureWarning", + "default:The compatibility profile '.*' has been renamed:FutureWarning", # Ignore deprecation warnings from external libraries we can't control # https://github.com/jawah/niquests/pull/327 https://github.com/jawah/niquests/issues/326 diff --git a/tests/docker-test-servers/zimbra/README.md b/tests/docker-test-servers/zimbra/README.md index 213b3d3a3..f73906c2c 100644 --- a/tests/docker-test-servers/zimbra/README.md +++ b/tests/docker-test-servers/zimbra/README.md @@ -5,6 +5,7 @@ Zimbra Collaboration Suite running in Docker for the caldav library test suite. ## Overview - **Image**: `zimbra/zcs-foss:latest` (Zimbra 8.8.3 pre-installed) +- **Compatibility profile**: `zimbra_8_8`. `zimbra_10_1` describes Zimbra 10.1, which has no docker image. - **Port**: 8808 (mapped to container's 443/HTTPS) - **Users**: testuser@zimbra.io / testpass, testuser2@zimbra.io / testpass - **Protocol**: HTTPS with self-signed certificate (`ssl_verify_cert=False`) diff --git a/tests/test_async_integration.py b/tests/test_async_integration.py index f7bb82220..e3032ce74 100644 --- a/tests/test_async_integration.py +++ b/tests/test_async_integration.py @@ -21,6 +21,7 @@ from caldav import Event, FreeBusy, Todo from caldav.compatibility_hints import FeatureSet, write_delay +from caldav.config import resolve_features from caldav.lib import error from .search_cache_delay import SearchCacheDelay @@ -175,14 +176,7 @@ class AsyncFunctionalTestsBaseClass: def _features(self): """Cached FeatureSet from server config.""" if not hasattr(self.__class__, "_feature_set_cache"): - features = self.server.features - if isinstance(features, str): - import caldav.compatibility_hints - - name = features - if name.startswith("compatibility_hints."): - name = name[len("compatibility_hints.") :] - features = getattr(caldav.compatibility_hints, name) + features = resolve_features(self.server.features) self.__class__._feature_set_cache = FeatureSet(features) return self.__class__._feature_set_cache diff --git a/tests/test_caldav_unit.py b/tests/test_caldav_unit.py index aa5c16d86..64bcec43d 100755 --- a/tests/test_caldav_unit.py +++ b/tests/test_caldav_unit.py @@ -4974,9 +4974,18 @@ def test_testing_allowed_is_deprecated(self, tmp_path): from caldav.config import get_all_test_servers config_file = self._write(tmp_path, {"testing_allowed": True}) - with pytest.warns(DeprecationWarning, match="test_allowed"): + with pytest.warns(FutureWarning, match="test_allowed"): assert "srv" in get_all_test_servers(config_file) + def test_deprecated_key_does_not_break_the_test_run(self, tmp_path): + """pyproject.toml's filterwarnings must let the warning through + rather than turn the developer's own config into a test error.""" + from caldav.config import get_all_test_servers, resolve_features + + config_file = self._write(tmp_path, {"testing_allowed": True}) + assert "srv" in get_all_test_servers(config_file) + resolve_features("zimbra") + def test_test_priority(self, tmp_path): from caldav.config import _ConfiguredServer, get_all_test_servers @@ -4989,7 +4998,7 @@ def test_priority_is_deprecated(self, tmp_path): from caldav.config import _ConfiguredServer, get_all_test_servers config_file = self._write(tmp_path, {"test_allowed": True, "priority": 5}) - with pytest.warns(DeprecationWarning, match="test_priority"): + with pytest.warns(FutureWarning, match="test_priority"): params = get_all_test_servers(config_file)["srv"] assert _ConfiguredServer("srv", params).priority == 5 @@ -4997,7 +5006,7 @@ def test_embedded_server_priority(self): from caldav.testing import RadicaleServer assert RadicaleServer({"test_priority": 3}).priority == 3 - with pytest.warns(DeprecationWarning, match="test_priority"): + with pytest.warns(FutureWarning, match="test_priority"): assert RadicaleServer({"priority": 4}).priority == 4 @@ -8630,7 +8639,7 @@ def test_recurrence_instance_keeps_search(self, base) -> None: assert [m for m, _ in sent][0] == "REPORT" assert sent[-1][1]["if-none-match"] == "*" - @pytest.mark.parametrize("server", ["zimbra", "sogo"]) + @pytest.mark.parametrize("server", ["zimbra_8_8", "zimbra_10_1", "sogo"]) def test_hints_of_servers_overwriting(self, server) -> None: from caldav import compatibility_hints from caldav.compatibility_hints import FeatureSet @@ -8975,7 +8984,9 @@ def test_recurrence_instance_keeps_search(self, base) -> None: ) assert [m for m, _ in sent] == ["REPORT"] - @pytest.mark.parametrize("server", ["radicale", "zimbra", "bedework_5_0_0", "sogo"]) + @pytest.mark.parametrize( + "server", ["radicale", "zimbra_8_8", "zimbra_10_1", "bedework_5_0_0", "sogo"] + ) def test_hints_of_servers_mishandling_if_match_star(self, server) -> None: from caldav import compatibility_hints from caldav.compatibility_hints import FeatureSet diff --git a/tests/test_compatibility_hints.py b/tests/test_compatibility_hints.py index 17ffbd1b8..4a0fd596f 100644 --- a/tests/test_compatibility_hints.py +++ b/tests/test_compatibility_hints.py @@ -11,6 +11,7 @@ import pytest +from caldav import compatibility_hints as ch from caldav.compatibility_hints import VALID_SUPPORT_LEVELS, FeatureSet, write_delay from caldav.config import resolve_features as _resolve_features @@ -549,16 +550,12 @@ def test_none_returns_none(self) -> None: assert _resolve_features(None) is None def test_string_resolves_profile(self) -> None: - import caldav.compatibility_hints as ch - result = _resolve_features("synology") assert result == ch.synology # deepcopy ensures the caller cannot mutate the shared profile assert result is not ch.synology def test_string_with_prefix(self) -> None: - import caldav.compatibility_hints as ch - result = _resolve_features("compatibility_hints.synology") assert result == ch.synology assert result is not ch.synology @@ -569,8 +566,6 @@ def test_dict_without_base_passes_through(self) -> None: assert result is features def test_base_with_overrides(self) -> None: - import caldav.compatibility_hints as ch - original_sync_token = ch.synology.get("sync-token") features = { "base": "synology", @@ -614,8 +609,6 @@ class TestRenamedProfiles: """ def test_bedework_profile_was_version_stamped(self) -> None: - import caldav.compatibility_hints as ch - assert hasattr(ch, "bedework_3_10_3") assert not hasattr(ch, "bedework") @@ -638,12 +631,40 @@ def test_renamed_name_as_base_explains_itself(self) -> None: assert "bedework_3_10_3" in str(exc_info.value) def test_new_name_resolves(self) -> None: - import caldav.compatibility_hints as ch - result = _resolve_features("bedework_3_10_3") assert result == ch.bedework_3_10_3 assert result is not ch.bedework_3_10_3 + def test_zimbra_profile_was_version_stamped(self) -> None: + assert hasattr(ch, "zimbra_8_8") + assert hasattr(ch, "zimbra_10_1") + assert "zimbra" not in vars(ch) + + def test_deprecated_zimbra_name_still_resolves(self) -> None: + """A config naming the old profile gets a FutureWarning: a + DeprecationWarning raised inside caldav.config is hidden by Python's + default filters, so the user would never be told to update it.""" + for name in ("zimbra", "compatibility_hints.zimbra"): + with pytest.warns(FutureWarning, match="zimbra_10_1"): + assert _resolve_features(name) == ch.zimbra_8_8 + with pytest.warns(FutureWarning, match="zimbra_8_8"): + result = _resolve_features({"base": "zimbra", "sync-token": "full"}) + assert result["sync-token"] == "full" + + def test_deprecated_zimbra_attribute_still_resolves(self) -> None: + with pytest.warns(DeprecationWarning, match="zimbra_8_8"): + assert ch.zimbra is ch.zimbra_8_8 + with pytest.warns(DeprecationWarning, match="zimbra_8_8"): + from caldav.compatibility_hints import zimbra + assert zimbra is ch.zimbra_8_8 + with pytest.raises(AttributeError): + ch.no_such_profile # noqa: B018 + + def test_zimbra_10_1_refuses_a_taken_uid_with_412(self) -> None: + assert ch.zimbra_10_1["save.no-uid-conflict"]["status"] == 412 + assert ch.zimbra_8_8["save.no-uid-conflict"] == {"support": "full"} + assert ch.zimbra_10_1["save-load.stable-url"] == ch.zimbra_8_8["save-load.stable-url"] + def test_unknown_profile_names_the_offender(self) -> None: with pytest.raises(ValueError) as exc_info: _resolve_features("no_such_server") diff --git a/tests/test_uid_lookup_fallback.py b/tests/test_uid_lookup_fallback.py index 85d9fa610..78b5722d3 100644 --- a/tests/test_uid_lookup_fallback.py +++ b/tests/test_uid_lookup_fallback.py @@ -383,7 +383,9 @@ def test_robur_skips_the_search(self): assert cal.get_event_by_uid(UID).id == UID assert methods(cal) == ["GET", "REPORT"] - @pytest.mark.parametrize("profile", ["zimbra", "bedework_3_10_3", "bedework_5_0_0"]) + @pytest.mark.parametrize( + "profile", ["zimbra_8_8", "zimbra_10_1", "bedework_3_10_3", "bedework_5_0_0"] + ) def test_profiles_with_a_working_uid_search_keep_it(self, profile): from caldav import compatibility_hints