From f9f2cc8ca3f61587009391260c3b0fb8d055cd3d Mon Sep 17 00:00:00 2001 From: Kostis-S-Z Date: Wed, 29 Jul 2026 12:23:20 +0300 Subject: [PATCH] Remove legacy API url warning --- docs/library_development.md | 3 -- src/datacollective/api_utils.py | 28 +----------------- tests/test_api_utils.py | 51 +++------------------------------ 3 files changed, 5 insertions(+), 77 deletions(-) diff --git a/docs/library_development.md b/docs/library_development.md index da59d19..5b00074 100644 --- a/docs/library_development.md +++ b/docs/library_development.md @@ -25,9 +25,6 @@ MDC_API_URL=https://your-dev-environment.example/api Notes: - The override applies to the SDK API requests. -- The cutover compatibility shim rewrites the legacy production host - `https://datacollective.mozillafoundation.org/api` to - `https://mozilladatacollective.com/api`. - Custom non-production URLs are passed through unchanged. ## Live E2E tests diff --git a/src/datacollective/api_utils.py b/src/datacollective/api_utils.py index a7c3c8b..57bb800 100644 --- a/src/datacollective/api_utils.py +++ b/src/datacollective/api_utils.py @@ -1,6 +1,5 @@ import os import platform -import warnings from pathlib import Path from typing import Any @@ -13,7 +12,6 @@ DEFAULT_API_URL = "https://mozilladatacollective.com/api" -LEGACY_API_URL = "https://datacollective.mozillafoundation.org/api" SCHEMA_REGISTRY_RAW_BASE_URL = ( "https://raw.githubusercontent.com/Mozilla-Data-Collective/dataset-schema-registry" ) @@ -21,7 +19,6 @@ ENV_API_URL = "MDC_API_URL" ENV_DOWNLOAD_PATH = "MDC_DOWNLOAD_PATH" HTTP_TIMEOUT = (10, 60) # (connect, read) -_LEGACY_API_URL_NOTICE_EMITTED = False _SENSITIVE_KEY_SUBSTRINGS = ( "url", "token", @@ -115,30 +112,7 @@ def _send_api_request( def _get_api_url() -> str: - configured_url = os.getenv(ENV_API_URL, DEFAULT_API_URL).rstrip("/") - # Overwrite legacy URL during runtime - if configured_url == LEGACY_API_URL: - _warn_legacy_api_url_once() - return DEFAULT_API_URL - return configured_url - - -def _warn_legacy_api_url_once() -> None: - global _LEGACY_API_URL_NOTICE_EMITTED - - if _LEGACY_API_URL_NOTICE_EMITTED: - return None - - _LEGACY_API_URL_NOTICE_EMITTED = True - message = ( - f"`{ENV_API_URL}` is set to the legacy API URL `{LEGACY_API_URL}`. " - f"The SDK is using `{DEFAULT_API_URL}` instead. " - f"Update the variable `{ENV_API_URL}` in your `.env` file to the new URL" - f", or completely remove `{ENV_API_URL}` to use the SDK default." - ) - warnings.warn(message, FutureWarning, stacklevel=3) - logger.warning(message) - return None + return os.getenv(ENV_API_URL, DEFAULT_API_URL).rstrip("/") def _extract_error_detail(resp: requests.Response) -> str: diff --git a/tests/test_api_utils.py b/tests/test_api_utils.py index 144dece..a90c8fc 100644 --- a/tests/test_api_utils.py +++ b/tests/test_api_utils.py @@ -1,6 +1,4 @@ -import logging import re -import warnings import datacollective.api_utils as api_utils @@ -19,58 +17,17 @@ def test_get_user_agent_appends_download_source_token() -> None: assert user_agent.endswith("source function: load_dataset") -def test_get_api_url_uses_new_default_without_warning(monkeypatch) -> None: +def test_get_api_url_uses_new_default(monkeypatch) -> None: monkeypatch.delenv(api_utils.ENV_API_URL, raising=False) - monkeypatch.setattr(api_utils, "_LEGACY_API_URL_NOTICE_EMITTED", False) - with warnings.catch_warnings(record=True) as caught: - warnings.simplefilter("always") - api_url = api_utils._get_api_url() + assert api_utils._get_api_url() == api_utils.DEFAULT_API_URL - assert api_url == api_utils.DEFAULT_API_URL - assert not caught - -def test_get_api_url_rewrites_legacy_env_and_warns_once(monkeypatch, caplog) -> None: - monkeypatch.setenv(api_utils.ENV_API_URL, api_utils.LEGACY_API_URL) - monkeypatch.setattr(api_utils, "_LEGACY_API_URL_NOTICE_EMITTED", False) - - with ( - warnings.catch_warnings(record=True) as caught, - caplog.at_level(logging.WARNING, logger="datacollective.api_utils"), - ): - warnings.simplefilter("always") - first_url = api_utils._get_api_url() - second_url = api_utils._get_api_url() - - assert first_url == api_utils.DEFAULT_API_URL - assert second_url == api_utils.DEFAULT_API_URL - assert len(caught) == 1 - - warning_message = str(caught[0].message) - assert api_utils.LEGACY_API_URL in warning_message - assert api_utils.DEFAULT_API_URL in warning_message - assert "set to the legacy API URL" in warning_message - - logged_messages = [ - record.getMessage() - for record in caplog.records - if record.name == "datacollective.api_utils" - ] - assert logged_messages == [warning_message] - - -def test_get_api_url_preserves_custom_url_without_warning(monkeypatch) -> None: +def test_get_api_url_preserves_custom_url(monkeypatch) -> None: custom_url = "https://api.example.test/custom" monkeypatch.setenv(api_utils.ENV_API_URL, custom_url) - monkeypatch.setattr(api_utils, "_LEGACY_API_URL_NOTICE_EMITTED", False) - - with warnings.catch_warnings(record=True) as caught: - warnings.simplefilter("always") - api_url = api_utils._get_api_url() - assert api_url == "https://api.example.test/custom" - assert not caught + assert api_utils._get_api_url() == custom_url def test_redact_sensitive_masks_urls_tokens_and_emails() -> None: