: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(subscriptions): require interval on create to avoid NoneType crash (#61477)
posthog[bot]ab75a13ee7aa
diff --git a/ee/api/subscription.py b/ee/api/subscription.pyindex 1dd700b2814f..fe8a390f7ecb 100644--- a/ee/api/subscription.py+++ b/ee/api/subscription.py@@ -164,7 +164,12 @@ class SubscriptionSerializer(serializers.ModelSerializer):},"frequency": {"help_text": "How often to deliver: daily, weekly, monthly, or yearly."},"interval": {- "help_text": "Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1."+ "required": True,+ "min_value": 1,+ "help_text": (+ "Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). "+ "Required on create; must be 1 or greater."+ ),},"byweekday": {"help_text": "Days of week for weekly subscriptions: monday, tuesday, wednesday, thursday, friday, saturday, sunday."diff --git a/ee/api/test/test_subscription.py b/ee/api/test/test_subscription.pyindex a4812ccfdd2f..815ed50814f2 100644--- a/ee/api/test/test_subscription.py+++ b/ee/api/test/test_subscription.py@@ -143,6 +143,29 @@ class TestSubscriptionTemporal(APILicensedTest):self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)assert "must have an insight, a dashboard, or a prompt" in str(response.json())+ @parameterized.expand(+ [+ ("missing", None),+ ("zero", 0),+ ("negative", -1),+ ]+ )+ def test_cannot_create_subscription_with_invalid_interval(self, _name: str, interval: Optional[int]):+ payload = {+ "insight": self.insight.id,+ "target_type": "email",+ "target_value": "[email protected]",+ "frequency": "weekly",+ "start_date": "2022-01-01T00:00:00",+ "title": "Invalid interval",+ }+ if interval is not None:+ payload["interval"] = interval++ response = self.client.post(f"/api/projects/{self.team.id}/subscriptions", payload)+ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)+ assert response.json().get("attr") == "interval"+def test_can_update_subscription_without_resending_relation(self):sub_id = self._create_subscription().json()["id"]response = self.client.patch(f"/api/projects/{self.team.id}/subscriptions/{sub_id}", {"title": "Updated title"})diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.tsindex 1b61287fc41d..36aa1ef80887 100644--- a/frontend/src/generated/core/api.schemas.ts+++ b/frontend/src/generated/core/api.schemas.ts@@ -2659,11 +2659,11 @@ export interface SubscriptionApi {* `yearly` - Yearly */frequency: SubscriptionFrequencyEnumApi/**- * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.- * @minimum -2147483648+ * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.+ * @minimum 1* @maximum 2147483647*/- interval?: number+ interval: number/*** Days of week for weekly subscriptions: monday, tuesday, wednesday, thursday, friday, saturday, sunday.* @nullable@@ -2789,8 +2789,8 @@ export interface PatchedSubscriptionApi {* `yearly` - Yearly */frequency?: SubscriptionFrequencyEnumApi/**- * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.- * @minimum -2147483648+ * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.+ * @minimum 1* @maximum 2147483647*/interval?: numberdiff --git a/frontend/src/generated/core/api.zod.ts b/frontend/src/generated/core/api.zod.tsindex 7b530f4a130d..d2a06d5d767c 100644--- a/frontend/src/generated/core/api.zod.ts+++ b/frontend/src/generated/core/api.zod.ts@@ -3182,7 +3182,6 @@ export const SessionRecordingsSharingRefreshCreateBody = /* @__PURE__ */ zod.objpassword_required: zod.boolean().optional(),})-export const subscriptionsCreateBodyIntervalMin = -2147483648export const subscriptionsCreateBodyIntervalMax = 2147483647export const subscriptionsCreateBodyBysetposMin = -2147483648@@ -3230,10 +3229,11 @@ export const SubscriptionsCreateBody = /* @__PURE__ */ zod),interval: zod.number()- .min(subscriptionsCreateBodyIntervalMin)+ .min(1).max(subscriptionsCreateBodyIntervalMax)- .optional()- .describe('Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.'),+ .describe(+ 'Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.'+ ),byweekday: zod.array(zod@@ -3288,7 +3288,6 @@ export const SubscriptionsCreateBody = /* @__PURE__ */ zod}).describe('Standard Subscription serializer.')-export const subscriptionsUpdateBodyIntervalMin = -2147483648export const subscriptionsUpdateBodyIntervalMax = 2147483647export const subscriptionsUpdateBodyBysetposMin = -2147483648@@ -3336,10 +3335,11 @@ export const SubscriptionsUpdateBody = /* @__PURE__ */ zod),interval: zod.number()- .min(subscriptionsUpdateBodyIntervalMin)+ .min(1).max(subscriptionsUpdateBodyIntervalMax)- .optional()- .describe('Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.'),+ .describe(+ 'Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.'+ ),byweekday: zod.array(zod@@ -3394,7 +3394,6 @@ export const SubscriptionsUpdateBody = /* @__PURE__ */ zod}).describe('Standard Subscription serializer.')-export const subscriptionsPartialUpdateBodyIntervalMin = -2147483648export const subscriptionsPartialUpdateBodyIntervalMax = 2147483647export const subscriptionsPartialUpdateBodyBysetposMin = -2147483648@@ -3445,10 +3444,12 @@ export const SubscriptionsPartialUpdateBody = /* @__PURE__ */ zod),interval: zod.number()- .min(subscriptionsPartialUpdateBodyIntervalMin)+ .min(1).max(subscriptionsPartialUpdateBodyIntervalMax).optional()- .describe('Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.'),+ .describe(+ 'Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.'+ ),byweekday: zod.array(zoddiff --git a/services/mcp/definitions/core.yaml b/services/mcp/definitions/core.yamlindex 19b9b463cea1..0c00a091d5d4 100644--- a/services/mcp/definitions/core.yaml+++ b/services/mcp/definitions/core.yaml@@ -458,8 +458,9 @@ tools:insight ID or dashboard ID. Set target_type to email, slack, or webhook and target_value to therecipient(s). For email: comma-separated addresses. For slack: requires an integration_id for a connectedSlack workspace plus a channel name in target_value. For webhook: a URL. Set frequency (daily, weekly,- monthly, yearly) and optionally interval, byweekday, start_date, and until_date. Dashboard subscriptions- also require dashboard_export_insights (list of insight IDs from that dashboard, max 6).+ monthly, yearly) and interval (the multiplier, e.g. 2 with weekly means every 2 weeks; required, minimum 1 —+ use 1 for no multiplier). byweekday, start_date, and until_date are optional. Dashboard subscriptions also+ require dashboard_export_insights (list of insight IDs from that dashboard, max 6).exclude_params:- created_by- next_delivery_datediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex ec0115aa806e..ed72989b4ddf 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -4725,7 +4725,7 @@}},"subscriptions-create": {- "description": "Create a new subscription to receive scheduled deliveries of an insight or dashboard. Requires either an insight ID or dashboard ID. Set target_type to email, slack, or webhook and target_value to the recipient(s). For email: comma-separated addresses. For slack: requires an integration_id for a connected Slack workspace plus a channel name in target_value. For webhook: a URL. Set frequency (daily, weekly, monthly, yearly) and optionally interval, byweekday, start_date, and until_date. Dashboard subscriptions also require dashboard_export_insights (list of insight IDs from that dashboard, max 6).",+ "description": "Create a new subscription to receive scheduled deliveries of an insight or dashboard. Requires either an insight ID or dashboard ID. Set target_type to email, slack, or webhook and target_value to the recipient(s). For email: comma-separated addresses. For slack: requires an integration_id for a connected Slack workspace plus a channel name in target_value. For webhook: a URL. Set frequency (daily, weekly, monthly, yearly) and interval (the multiplier, e.g. 2 with weekly means every 2 weeks; required, minimum 1 — use 1 for no multiplier). byweekday, start_date, and until_date are optional. Dashboard subscriptions also require dashboard_export_insights (list of insight IDs from that dashboard, max 6).","category": "Core","feature": "core","summary": "Create subscription",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 61f7d424a21b..07fe9b53766b 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -5052,7 +5052,7 @@}},"subscriptions-create": {- "description": "Create a new subscription to receive scheduled deliveries of an insight or dashboard. Requires either an insight ID or dashboard ID. Set target_type to email, slack, or webhook and target_value to the recipient(s). For email: comma-separated addresses. For slack: requires an integration_id for a connected Slack workspace plus a channel name in target_value. For webhook: a URL. Set frequency (daily, weekly, monthly, yearly) and optionally interval, byweekday, start_date, and until_date. Dashboard subscriptions also require dashboard_export_insights (list of insight IDs from that dashboard, max 6).",+ "description": "Create a new subscription to receive scheduled deliveries of an insight or dashboard. Requires either an insight ID or dashboard ID. Set target_type to email, slack, or webhook and target_value to the recipient(s). For email: comma-separated addresses. For slack: requires an integration_id for a connected Slack workspace plus a channel name in target_value. For webhook: a URL. Set frequency (daily, weekly, monthly, yearly) and interval (the multiplier, e.g. 2 with weekly means every 2 weeks; required, minimum 1 — use 1 for no multiplier). byweekday, start_date, and until_date are optional. Dashboard subscriptions also require dashboard_export_insights (list of insight IDs from that dashboard, max 6).","category": "Core","feature": "core","summary": "Create subscription",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex f04727685a1d..24298b75ac39 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -25091,11 +25091,11 @@ export namespace Schemas {* `yearly` - Yearly */frequency: SubscriptionFrequencyEnum;/**- * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.- * @minimum -2147483648+ * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.+ * @minimum 1* @maximum 2147483647*/- interval?: number;+ interval: number;/*** Days of week for weekly subscriptions: monday, tuesday, wednesday, thursday, friday, saturday, sunday.* @nullable@@ -30989,8 +30989,8 @@ export namespace Schemas {* `yearly` - Yearly */frequency?: SubscriptionFrequencyEnum;/**- * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.- * @minimum -2147483648+ * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.+ * @minimum 1* @maximum 2147483647*/interval?: number;diff --git a/services/mcp/src/generated/core/api.ts b/services/mcp/src/generated/core/api.tsindex 5e314669eeac..fc1e8da22e72 100644--- a/services/mcp/src/generated/core/api.ts+++ b/services/mcp/src/generated/core/api.ts@@ -301,7 +301,6 @@ export const SubscriptionsCreateParams = /* @__PURE__ */ zod.object({),})-export const subscriptionsCreateBodyIntervalMin = -2147483648export const subscriptionsCreateBodyIntervalMax = 2147483647export const subscriptionsCreateBodyBysetposMin = -2147483648@@ -349,10 +348,11 @@ export const SubscriptionsCreateBody = /* @__PURE__ */ zod),interval: zod.number()- .min(subscriptionsCreateBodyIntervalMin)+ .min(1).max(subscriptionsCreateBodyIntervalMax)- .optional()- .describe('Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.'),+ .describe(+ 'Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.'+ ),byweekday: zod.array(zod@@ -425,7 +425,6 @@ export const SubscriptionsPartialUpdateParams = /* @__PURE__ */ zod.object({),})-export const subscriptionsPartialUpdateBodyIntervalMin = -2147483648export const subscriptionsPartialUpdateBodyIntervalMax = 2147483647export const subscriptionsPartialUpdateBodyBysetposMin = -2147483648@@ -476,10 +475,12 @@ export const SubscriptionsPartialUpdateBody = /* @__PURE__ */ zod),interval: zod.number()- .min(subscriptionsPartialUpdateBodyIntervalMin)+ .min(1).max(subscriptionsPartialUpdateBodyIntervalMax).optional()- .describe('Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.'),+ .describe(+ 'Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.'+ ),byweekday: zod.array(zoddiff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-create.jsonindex f20d97e171df..8cbd33f69180 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-create.json@@ -98,9 +98,9 @@"description": "ID of a connected Slack integration. Required when target_type is slack."},"interval": {- "description": "Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.",+ "description": "Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.","maximum": 2147483647,- "minimum": -2147483648,+ "minimum": 1,"type": "number"},"invite_message": {@@ -162,6 +162,6 @@"description": "When to stop delivering (ISO 8601 datetime). Null for indefinite."}},- "required": ["target_type", "target_value", "frequency", "start_date"],+ "required": ["target_type", "target_value", "frequency", "interval", "start_date"],"type": "object"}diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-partial-update.jsonindex 333edf1f7dab..1d7a243c2b1f 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-partial-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-partial-update.json@@ -101,9 +101,9 @@"description": "ID of a connected Slack integration. Required when target_type is slack."},"interval": {- "description": "Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1.",+ "description": "Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.","maximum": 2147483647,- "minimum": -2147483648,+ "minimum": 1,"type": "number"},"invite_message": {