:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(warehouse-suggestions): ignore payload keys the code does not declare (#128123)
Thiago Salvatoref095f2b5e136
diff --git a/products/warehouse_suggestions/backend/logic/payloads.py b/products/warehouse_suggestions/backend/logic/payloads.pyindex 8733e4e92a43..6b2412dee8c6 100644--- a/products/warehouse_suggestions/backend/logic/payloads.py+++ b/products/warehouse_suggestions/backend/logic/payloads.py@@ -36,13 +36,14 @@ def payload_from_json(if payload_version != PAYLOAD_VERSION:raise UnsupportedPayloadVersionError(payload_version)if kind == WarehouseSuggestionKind.CERTIFY:- return CertifyPayload(**data)+ return CertifyPayload(**_declared(CertifyPayload, data))if kind == WarehouseSuggestionKind.DEPRECATE:- return DeprecatePayload(**data)+ return DeprecatePayload(**_declared(DeprecatePayload, data))if kind == WarehouseSuggestionKind.UNMATERIALIZE:- return UnmaterializePayload(**data)- sources = {field: tuple(_source_ref(source) for source in data[field]) for field in SOURCE_FIELDS}- return MaterializePayload(**{**data, **sources, **_refresh_fields(data)})+ return UnmaterializePayload(**_declared(UnmaterializePayload, data))+ declared = _declared(MaterializePayload, data)+ sources = {field: tuple(_source_ref(source) for source in declared[field]) for field in SOURCE_FIELDS}+ return MaterializePayload(**{**declared, **sources, **_refresh_fields(declared)})def source_table_ids(payloads: Iterable[SuggestionPayload]) -> set[UUID]:@@ -75,6 +76,11 @@ def _visible_sources(sources: tuple[SourceRef, ...], readable_table_ids: Collectreturn VisibleSources(names=names, hidden_count=len(sources) - len(names))+def _declared(payload_type: type, data: Mapping[str, Any]) -> dict[str, Any]:+ names = {field.name for field in fields(payload_type)}+ return {key: value for key, value in data.items() if key in names}++def _source_ref(source: Mapping[str, Any]) -> SourceRef:table_id = source["warehouse_table_id"]return SourceRef(name=source["name"], warehouse_table_id=UUID(table_id) if table_id else None)diff --git a/products/warehouse_suggestions/backend/tests/test_payloads.py b/products/warehouse_suggestions/backend/tests/test_payloads.pynew file mode 100644index 000000000000..2cf141524876--- /dev/null+++ b/products/warehouse_suggestions/backend/tests/test_payloads.py@@ -0,0 +1,17 @@+from django.test import SimpleTestCase++from parameterized import parameterized++from products.warehouse_suggestions.backend.facade.contracts import PAYLOAD_VERSION+from products.warehouse_suggestions.backend.facade.enums import WarehouseSuggestionKind+from products.warehouse_suggestions.backend.logic.payloads import payload_from_json, payload_to_json++from .test_lifecycle import PAYLOADS+++class TestPayloadFromJson(SimpleTestCase):+ @parameterized.expand([(kind.value, kind) for kind in WarehouseSuggestionKind])+ def test_ignores_keys_a_newer_release_wrote(self, _name: str, kind: WarehouseSuggestionKind) -> None:+ stored = {**payload_to_json(PAYLOADS[kind]), "written_by_a_newer_release": 1}++ assert payload_from_json(kind, PAYLOAD_VERSION, stored) == PAYLOADS[kind]