: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: unknownFutureValue (#64687)
Alex V5e175bbdffd4
diff --git a/products/conversations/backend/api/tests/test_teams_shared_channel_polling.py b/products/conversations/backend/api/tests/test_teams_shared_channel_polling.pyindex dc6b40ca5501..ecf5c0fdadbe 100644--- a/products/conversations/backend/api/tests/test_teams_shared_channel_polling.py+++ b/products/conversations/backend/api/tests/test_teams_shared_channel_polling.py@@ -215,6 +215,28 @@ class TestPollSharedChannel(BaseTest):poll_team_shared_channels(self.team.id)self.assertEqual(Ticket.objects.filter(team=self.team).count(), 0)+ @patch("products.conversations.backend.tasks.requests.get")+ def test_unknown_future_value_passes_verification(self, mock_get: MagicMock, *_: Any) -> None:+ # Graph reports shared channels as "unknownFutureValue" in some tenants — must still poll.+ mock_get.side_effect = [+ _resp(json_data={"id": CHANNEL_ID, "membershipType": "unknownFutureValue"}),+ _resp(json_data={"value": [], "@odata.deltaLink": "DELTA1"}),+ ]+ poll_team_shared_channels(self.team.id)+ self.assertTrue(self._sync().primed)++ @parameterized.expand([("standard", "standard"), ("private", "private")])+ @patch("products.conversations.backend.tasks.requests.get")+ def test_non_shared_channel_is_rejected_and_sync_deleted(+ self, _name: str, membership_type: str, mock_get: MagicMock, *_: Any+ ) -> None:+ mock_get.return_value = _resp(json_data={"id": CHANNEL_ID, "membershipType": membership_type})+ poll_team_shared_channels(self.team.id)++ self.assertFalse(+ TeamConversationsTeamsChannelSync.objects.for_team(self.team.id).filter(channel_id=CHANNEL_ID).exists()+ )+class TestStoreTeamsServiceUrl(BaseTest):def setUp(self) -> None:@@ -242,28 +264,26 @@ class TestStoreTeamsServiceUrl(BaseTest):self.assertIsNone(self.config.teams_service_url)-@patch("products.conversations.backend.tasks.poll_team_shared_channels.delay")class TestPollFanout(BaseTest):- def test_fans_out_only_teams_with_shared_channels(self, mock_delay: MagicMock) -> None:- # Team with a shared channel -> fanned out.- self.team.conversations_settings = {- "teams_enabled": True,- "teams_channels": [{"channel_id": CHANNEL_ID, "team_id": TEAMS_TEAM_ID, "membership_type": "shared"}],- }- self.team.save()- TeamConversationsTeamsConfig.objects.update_or_create(- team=self.team,- defaults={"teams_tenant_id": "tenant-abc", "teams_graph_access_token": "graph-tok"},- )-- poll_teams_shared_channels()-- mock_delay.assert_called_once_with(self.team.id)-- def test_skips_team_with_only_standard_channels(self, mock_delay: MagicMock) -> None:+ # Graph returns "unknownFutureValue" for shared channels in some tenants, so both+ # it and the literal "shared" must fan out; standard/private must not.+ @parameterized.expand(+ [+ ("shared", "shared", True),+ ("unknown_future_value", "unknownFutureValue", True),+ ("standard", "standard", False),+ ("private", "private", False),+ ]+ )+ @patch("products.conversations.backend.tasks.poll_team_shared_channels.delay")+ def test_fanout_by_membership_type(+ self, _name: str, membership_type: str, should_fan_out: bool, mock_delay: MagicMock+ ) -> None:self.team.conversations_settings = {"teams_enabled": True,- "teams_channels": [{"channel_id": CHANNEL_ID, "team_id": TEAMS_TEAM_ID, "membership_type": "standard"}],+ "teams_channels": [+ {"channel_id": CHANNEL_ID, "team_id": TEAMS_TEAM_ID, "membership_type": membership_type}+ ],}self.team.save()TeamConversationsTeamsConfig.objects.update_or_create(@@ -273,4 +293,7 @@ class TestPollFanout(BaseTest):poll_teams_shared_channels()- mock_delay.assert_not_called()+ if should_fan_out:+ mock_delay.assert_called_once_with(self.team.id)+ else:+ mock_delay.assert_not_called()diff --git a/products/conversations/backend/tasks.py b/products/conversations/backend/tasks.pyindex 8a7fb309dc68..4bf7ee8f779a 100644--- a/products/conversations/backend/tasks.py+++ b/products/conversations/backend/tasks.py@@ -828,12 +828,25 @@ def post_reply_to_teams(raise cast(Any, post_reply_to_teams).retry(exc=e)+# Graph's channel membershipType is an evolvable enum: the v1.0+# /teams/{id}/channels endpoint emits "unknownFutureValue" for shared channels in+# some tenants instead of the literal "shared". So we treat anything that isn't an+# explicit standard/private channel as pollable (shared), rather than matching+# "shared" exactly — and the Graph re-verification below rejects only the explicit+# standard/private cases.+TEAMS_NON_POLLED_MEMBERSHIP_TYPES = {"standard", "private"}+++def _is_shared_membership_type(membership_type: str | None) -> bool:+ return membership_type not in TEAMS_NON_POLLED_MEMBERSHIP_TYPES++def _shared_channel_entries(support_settings: dict) -> list[dict]:- """Configured channels flagged as shared (the only ones the poller pulls)."""+ """Configured channels the poller pulls (shared/unknownFutureValue, not standard/private)."""entries = support_settings.get("teams_channels")if not isinstance(entries, list):return []- return [e for e in entries if isinstance(e, dict) and e.get("membership_type") == "shared"]+ return [e for e in entries if isinstance(e, dict) and _is_shared_membership_type(e.get("membership_type"))]def _parse_graph_datetime(value: str | None) -> datetime | None:@@ -876,13 +889,15 @@ def _poll_one_shared_channel(# On first encounter, verify via Graph that the channel is actually shared.# conversations_settings is client-mutable, so we don't trust its# membership_type — we confirm from the authoritative source before polling.+ # Graph returns "unknownFutureValue" for shared channels in some tenants, so we+ # reject only explicit standard/private channels rather than requiring "shared".if created:ch_resp = requests.get(f"{GRAPH_API_BASE}/teams/{teams_team_id}/channels/{channel_id}",headers={"Authorization": f"Bearer {token}"},timeout=TEAMS_DELTA_REQUEST_TIMEOUT_SECONDS,)- if ch_resp.status_code != 200 or ch_resp.json().get("membershipType") != "shared":+ if ch_resp.status_code != 200 or not _is_shared_membership_type(ch_resp.json().get("membershipType")):logger.warning("poll_teams_shared_channel_not_shared",team_id=team.id,