diff --git a/ldclient/async_config.py b/ldclient/async_config.py index 189b2a45..b46b362e 100644 --- a/ldclient/async_config.py +++ b/ldclient/async_config.py @@ -245,7 +245,7 @@ def __init__( :param plugins: A list of plugins to be used with the SDK. Plugin support is currently experimental and subject to change. :param enable_event_compression: Whether or not to enable GZIP compression for outgoing events. :param omit_anonymous_contexts: Sets whether anonymous contexts should be omitted from index and identify events. - :param payload_filter_key: The payload filter is used to selectively limited the flags and segments delivered in the data source payload. + :param payload_filter_key: The payload filter is used to selectively limited the flags and segments delivered in the data source payload. Payload filtering is not supported with the FDv2 data system, so this has no effect on FDv2 requests. :param datasystem_config: Configuration for the upcoming enhanced data system design. This is experimental and should not be set without direction from LaunchDarkly support. """ self.__sdk_key = validate_sdk_key_format(sdk_key, log) @@ -476,6 +476,9 @@ def payload_filter_key(self) -> Optional[str]: polling data sources. It will not affect TestData or FileData data sources, nor will it be applied to any data source provided through the {#data_source} config property. + + Payload filtering is not supported with the FDv2 data system, so this + key has no effect on requests made by FDv2 data sources. """ return self.__payload_filter_key diff --git a/ldclient/config.py b/ldclient/config.py index 24ce58af..d7ac76a2 100644 --- a/ldclient/config.py +++ b/ldclient/config.py @@ -391,7 +391,7 @@ def __init__( :param plugins: A list of plugins to be used with the SDK. Plugin support is currently experimental and subject to change. :param enable_event_compression: Whether or not to enable GZIP compression for outgoing events. :param omit_anonymous_contexts: Sets whether anonymous contexts should be omitted from index and identify events. - :param payload_filter_key: The payload filter is used to selectively limited the flags and segments delivered in the data source payload. + :param payload_filter_key: The payload filter is used to selectively limited the flags and segments delivered in the data source payload. Payload filtering is not supported with the FDv2 data system, so this has no effect on FDv2 requests. :param datasystem_config: Configuration for the upcoming enhanced data system design. This is experimental and should not be set without direction from LaunchDarkly support. """ self.__sdk_key = validate_sdk_key_format(sdk_key, log) @@ -681,6 +681,9 @@ def payload_filter_key(self) -> Optional[str]: polling data sources. It will not affect TestData or FileData data sources, nor will it be applied to any data source provided through the {#data_source} config property. + + Payload filtering is not supported with the FDv2 data system, so this + key has no effect on requests made by FDv2 data sources. """ return self.__payload_filter_key diff --git a/ldclient/impl/datasystem/async_fdv2.py b/ldclient/impl/datasystem/async_fdv2.py index 02d9c826..c9d0388d 100644 --- a/ldclient/impl/datasystem/async_fdv2.py +++ b/ldclient/impl/datasystem/async_fdv2.py @@ -247,6 +247,10 @@ def __init__( self._config = config self._data_system_config = data_system_config + + if config.payload_filter_key is not None: + log.warning("Payload filtering is not supported with the FDv2 data system; the configured payload filter has no effect on FDv2 requests") + self._synchronizers: List[DataSourceBuilder[AsyncSynchronizer]] = list(data_system_config.synchronizers) if data_system_config.synchronizers else [] self._fdv1_fallback_synchronizer_builder = data_system_config.fdv1_fallback_synchronizer self._disabled = config.offline diff --git a/ldclient/impl/datasystem/fdv2.py b/ldclient/impl/datasystem/fdv2.py index c5164b7a..3455eab1 100644 --- a/ldclient/impl/datasystem/fdv2.py +++ b/ldclient/impl/datasystem/fdv2.py @@ -230,6 +230,10 @@ def __init__( self._config = config self._data_system_config = data_system_config + + if config.payload_filter_key is not None: + log.warning("Payload filtering is not supported with the FDv2 data system; the configured payload filter has no effect on FDv2 requests") + self._synchronizers: List[DataSourceBuilder[Synchronizer]] = list(data_system_config.synchronizers) if data_system_config.synchronizers else [] self._fdv1_fallback_synchronizer_builder = data_system_config.fdv1_fallback_synchronizer self._disabled = config.offline diff --git a/ldclient/testing/impl/datasystem/test_async_fdv2.py b/ldclient/testing/impl/datasystem/test_async_fdv2.py index 2411ac9e..1a0a2d88 100644 --- a/ldclient/testing/impl/datasystem/test_async_fdv2.py +++ b/ldclient/testing/impl/datasystem/test_async_fdv2.py @@ -1,6 +1,7 @@ # pylint: disable=missing-docstring import asyncio +import logging from typing import Any, AsyncGenerator, Dict, List, Mapping, Optional import pytest @@ -778,3 +779,17 @@ async def test_successful_ops_pass_through(): assert got is not None and got["key"] == "flag-a" allf = await wrapper.all(FEATURES) assert "flag-a" in allf + + +def test_warns_when_payload_filter_key_is_configured(caplog): + caplog.set_level(logging.WARNING, logger="ldclient.util") + AsyncFDv2(AsyncConfig(sdk_key="dummy", payload_filter_key="microservice-1"), DataSystemConfig(initializers=None, synchronizers=None)) + + assert any("Payload filtering is not supported with the FDv2 data system" in record.message for record in caplog.records) + + +def test_does_not_warn_when_payload_filter_key_is_not_configured(caplog): + caplog.set_level(logging.WARNING, logger="ldclient.util") + AsyncFDv2(AsyncConfig(sdk_key="dummy"), DataSystemConfig(initializers=None, synchronizers=None)) + + assert not any("Payload filtering" in record.message for record in caplog.records) diff --git a/ldclient/testing/impl/datasystem/test_fdv2_datasystem.py b/ldclient/testing/impl/datasystem/test_fdv2_datasystem.py index d4699e32..6cc98a85 100644 --- a/ldclient/testing/impl/datasystem/test_fdv2_datasystem.py +++ b/ldclient/testing/impl/datasystem/test_fdv2_datasystem.py @@ -1,5 +1,6 @@ # pylint: disable=missing-docstring +import logging import os import tempfile from threading import Event @@ -846,3 +847,17 @@ def test_environment_id_is_not_recorded_from_non_valid_updates(): assert fdv2.environment_id == "env-from-sync" fdv2.stop() + + +def test_warns_when_payload_filter_key_is_configured(caplog): + caplog.set_level(logging.WARNING, logger="ldclient.util") + FDv2(Config(sdk_key="dummy", payload_filter_key="microservice-1"), DataSystemConfig(initializers=None, synchronizers=None)) + + assert any("Payload filtering is not supported with the FDv2 data system" in record.message for record in caplog.records) + + +def test_does_not_warn_when_payload_filter_key_is_not_configured(caplog): + caplog.set_level(logging.WARNING, logger="ldclient.util") + FDv2(Config(sdk_key="dummy"), DataSystemConfig(initializers=None, synchronizers=None)) + + assert not any("Payload filtering" in record.message for record in caplog.records)