: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(schema): support array properties in event schemas (#122923)
Matt Pua7506b8c3c3e4
diff --git a/frontend/src/scenes/data-management/schema/schemaManagementLogic.ts b/frontend/src/scenes/data-management/schema/schemaManagementLogic.tsindex d068d6bedf45..1cf6b2970cce 100644--- a/frontend/src/scenes/data-management/schema/schemaManagementLogic.ts+++ b/frontend/src/scenes/data-management/schema/schemaManagementLogic.ts@@ -7,7 +7,7 @@ import api from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast'import { teamLogic } from 'scenes/teamLogic'-export type PropertyType = 'String' | 'Numeric' | 'Boolean' | 'DateTime' | 'Object'+export type PropertyType = 'String' | 'Numeric' | 'Boolean' | 'DateTime' | 'Object' | 'Array'export const MAX_PROPERTY_NAME_LENGTH = 200@@ -17,6 +17,7 @@ export const PROPERTY_TYPE_OPTIONS: { value: PropertyType; label: string }[] = [{ value: 'Boolean', label: 'Boolean' },{ value: 'DateTime', label: 'DateTime' },{ value: 'Object', label: 'Object' },+ { value: 'Array', label: 'Array' },]function getErrorMessage(error: any, defaultMessage: string): string {diff --git a/nodejs/src/ingestion/common/steps/event-preprocessing/validate-event-schema.test.ts b/nodejs/src/ingestion/common/steps/event-preprocessing/validate-event-schema.test.tsindex 093258e853a3..c217594fd20f 100644--- a/nodejs/src/ingestion/common/steps/event-preprocessing/validate-event-schema.test.ts+++ b/nodejs/src/ingestion/common/steps/event-preprocessing/validate-event-schema.test.ts@@ -221,16 +221,28 @@ describe('validateEventAgainstSchema', () => {})})- describe('Object type coercion', () => {- it.each([+ describe.each(['Object', 'Array'])('%s type coercion', (propertyType) => {+ const objectCases: [string, unknown][] = [['plain object', { foo: 'bar' }],['empty object', {}],+ ]+ const arrayCases: [string, unknown][] = [['array', [1, 2, 3]],['empty array', []],- ])('should accept %s as Object', (_, value) => {+ ['mixed array', [1, 'two', null, { nested: [true] }]],+ ]+ const primitiveCases: [string, unknown][] = [+ ['string', 'hello'],+ ['number', 42],+ ['boolean', true],+ ]+ const acceptCases = propertyType === 'Object' ? [...objectCases, ...arrayCases] : arrayCases+ const rejectCases = propertyType === 'Object' ? primitiveCases : [...objectCases, ...primitiveCases]++ it.each(acceptCases)('should accept %s', (_, value) => {const schema: EventSchemaEnforcement = {event_name: 'test_event',- required_properties: new Map([['prop', ['Object']]]),+ required_properties: new Map([['prop', [propertyType]]]),}const result = validateEventAgainstSchema({ prop: value }, schema)@@ -238,14 +250,10 @@ describe('validateEventAgainstSchema', () => {expect(result.valid).toBe(true)})- it.each([- ['string', 'hello'],- ['number', 42],- ['boolean', true],- ])('should reject %s as Object', (_, value) => {+ it.each(rejectCases)('should reject %s', (_, value) => {const schema: EventSchemaEnforcement = {event_name: 'test_event',- required_properties: new Map([['prop', ['Object']]]),+ required_properties: new Map([['prop', [propertyType]]]),}const result = validateEventAgainstSchema({ prop: value }, schema)diff --git a/nodejs/src/ingestion/common/steps/event-preprocessing/validate-event-schema.ts b/nodejs/src/ingestion/common/steps/event-preprocessing/validate-event-schema.tsindex 3b923f4e1bbc..39a6ee273b63 100644--- a/nodejs/src/ingestion/common/steps/event-preprocessing/validate-event-schema.ts+++ b/nodejs/src/ingestion/common/steps/event-preprocessing/validate-event-schema.ts@@ -45,6 +45,9 @@ function canCoerceToType(value: unknown, propertyType: string): boolean {case 'DateTime':return isValidClickHouseDateTime(value)+ case 'Array':+ return Array.isArray(value)+case 'Object':return typeof value === 'object'diff --git a/posthog/api/test/test_schema_property_group.py b/posthog/api/test/test_schema_property_group.pyindex ffb4def5df58..3bced5e919f3 100644--- a/posthog/api/test/test_schema_property_group.py+++ b/posthog/api/test/test_schema_property_group.py@@ -1,12 +1,14 @@from posthog.test.base import APIBaseTest+from parameterized import parameterizedfrom rest_framework import statusfrom posthog.models import EventDefinition, EventSchema, Project, SchemaPropertyGroup, SchemaPropertyGroupPropertyclass TestSchemaPropertyGroupAPI(APIBaseTest):- def test_create_property_group_with_properties(self):+ @parameterized.expand([("String",), ("Object",), ("Array",)])+ def test_create_property_group_with_properties(self, property_type: str) -> None:response = self.client.post(f"/api/projects/{self.project.id}/schema_property_groups/",{@@ -15,7 +17,7 @@ class TestSchemaPropertyGroupAPI(APIBaseTest):"properties": [{"name": "user_id",- "property_type": "String",+ "property_type": property_type,"is_required": True,"description": "User ID",},@@ -38,6 +40,31 @@ class TestSchemaPropertyGroupAPI(APIBaseTest):assert data["properties"][0]["is_required"] is Falseassert data["properties"][1]["name"] == "user_id"assert data["properties"][1]["is_required"] is True+ assert data["properties"][1]["property_type"] == property_type++ @parameterized.expand(+ [+ ("typescript", "any[]"),+ ("python", "List[Any]"),+ ("golang", "[]interface{}"),+ ]+ )+ def test_array_property_generates_array_type(self, language: str, expected_type: str) -> None:+ response = self.client.post(+ f"/api/projects/{self.project.id}/schema_property_groups/",+ {+ "name": "Basket",+ "properties": [{"name": "items", "property_type": "Array", "is_required": True}],+ },+ )+ assert response.status_code == status.HTTP_201_CREATED+ event = EventDefinition.objects.create(team=self.team, project=self.project, name="basket_saved")+ EventSchema.objects.create(event_definition=event, property_group_id=response.json()["id"])++ response = self.client.get(f"/api/projects/{self.project.id}/event_definitions/{language}/")++ assert response.status_code == status.HTTP_200_OK+ assert expected_type in response.json()["content"]def test_create_property_group_with_is_optional_in_types(self):response = self.client.post(diff --git a/products/event_definitions/backend/migrations/0016_add_array_schema_property_type.py b/products/event_definitions/backend/migrations/0016_add_array_schema_property_type.pynew file mode 100644index 000000000000..fb9ef751cc59--- /dev/null+++ b/products/event_definitions/backend/migrations/0016_add_array_schema_property_type.py@@ -0,0 +1,27 @@+# Generated by Django 5.2.18 on 2026-10-23 21:53++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("event_definitions", "0015_drop_index_property_def_query"),+ ]++ operations = [+ migrations.AlterField(+ model_name="schemapropertygroupproperty",+ name="property_type",+ field=models.CharField(+ choices=[+ ("DateTime", "DateTime"),+ ("String", "String"),+ ("Numeric", "Numeric"),+ ("Boolean", "Boolean"),+ ("Object", "Object"),+ ("Array", "Array"),+ ],+ max_length=50,+ ),+ ),+ ]diff --git a/products/event_definitions/backend/migrations/max_migration.txt b/products/event_definitions/backend/migrations/max_migration.txtindex 4469ee86d027..d4d0baf7b950 100644--- a/products/event_definitions/backend/migrations/max_migration.txt+++ b/products/event_definitions/backend/migrations/max_migration.txt@@ -1 +1 @@-0015_drop_index_property_def_query+0016_add_array_schema_property_typediff --git a/products/event_definitions/backend/models/schema.py b/products/event_definitions/backend/models/schema.pyindex 584a94d64fdf..9dea4fd1aa51 100644--- a/products/event_definitions/backend/models/schema.py+++ b/products/event_definitions/backend/models/schema.py@@ -14,6 +14,7 @@ class SchemaPropertyType(models.TextChoices):Numeric = "Numeric", "Numeric"Boolean = "Boolean", "Boolean"Object = "Object", "Object"+ Array = "Array", "Array"class SchemaPropertyGroup(UUIDTModel):diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 0bcd2617d3e1..0dfa2cbbb308 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -46686,6 +46686,7 @@ export namespace Schemas {* * `Numeric` - Numeric* * `Boolean` - Boolean* * `Object` - Object+ * * `Array` - Array*/export type SchemaPropertyTypeEnum = typeof SchemaPropertyTypeEnum[keyof typeof SchemaPropertyTypeEnum];@@ -46696,6 +46697,7 @@ export namespace Schemas {Numeric: 'Numeric',Boolean: 'Boolean',Object: 'Object',+ Array: 'Array',} as const;export interface SchemaPropertyGroupProperty {