Skip to content

: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.

fix(feature-flags): guard wordPluralize against null group_type (#61076)

posthog[bot]8d5625e3766e
diff --git a/frontend/src/lib/utils.test.ts b/frontend/src/lib/utils.test.ts
index 6ece06cfa1af..0120d116d566 100644
--- a/frontend/src/lib/utils.test.ts
+++ b/frontend/src/lib/utils.test.ts
@@ -231,6 +231,12 @@ describe('lib/utils', () => {
expect(wordPluralize('child')).toEqual('children')
expect(wordPluralize('knife')).toEqual('knives')
})
+
+ it('returns falsy input unchanged without throwing', () => {
+ expect(wordPluralize('')).toEqual('')
+ expect(wordPluralize(null as unknown as string)).toEqual('')
+ expect(wordPluralize(undefined as unknown as string)).toEqual('')
+ })
})
describe('endWithPunctation()', () => {
diff --git a/frontend/src/lib/utils.tsx b/frontend/src/lib/utils.tsx
index 6e286f07c15d..ba4ce6795b79 100644
--- a/frontend/src/lib/utils.tsx
+++ b/frontend/src/lib/utils.tsx
@@ -1850,6 +1850,10 @@ const WORD_PLURALIZATION_RULES = [
] as [RegExp, string][]
export function wordPluralize(word: string): string {
+ if (!word) {
+ return word ?? ''
+ }
+
let len = WORD_PLURALIZATION_RULES.length
// Iterate over the sanitization rules and use the first one to match.
diff --git a/frontend/src/models/groupsModel.ts b/frontend/src/models/groupsModel.ts
index 51171cc1bb42..e11b92105089 100644
--- a/frontend/src/models/groupsModel.ts
+++ b/frontend/src/models/groupsModel.ts
@@ -122,8 +122,8 @@ export const groupsModel = kea<groupsModelType>([
const groupType = groupTypes.get(groupTypeIndex as GroupTypeIndex)
if (groupType) {
return {
- singular: groupType.name_singular || groupType.group_type,
- plural: groupType.name_plural || wordPluralize(groupType.group_type),
+ singular: groupType.name_singular || groupType.group_type || 'group',
+ plural: groupType.name_plural || wordPluralize(groupType.group_type) || 'groups',
}
}
return {
diff --git a/posthog/personhog_client/converters.py b/posthog/personhog_client/converters.py
index 8be46c07e7cd..83dc85362e3e 100644
--- a/posthog/personhog_client/converters.py
+++ b/posthog/personhog_client/converters.py
@@ -27,7 +27,9 @@ def proto_group_type_mapping_to_dict(mapping: group_pb2.GroupTypeMapping) -> dic
created_at = datetime.fromtimestamp(mapping.created_at / 1000, tz=UTC)
return {
- "group_type": mapping.group_type or None,
+ # group_type is NOT NULL in the DB, so mirror the ORM .values() path and keep it a string.
+ # Coercing a falsy value to None here leaks a null group_type to the frontend, which crashes wordPluralize.
+ "group_type": mapping.group_type,
"group_type_index": mapping.group_type_index,
"name_singular": mapping.name_singular or None,
"name_plural": mapping.name_plural or None,
diff --git a/posthog/personhog_client/test_converters.py b/posthog/personhog_client/test_converters.py
index f0e8fa68f2ee..bfa6f944ebe0 100644
--- a/posthog/personhog_client/test_converters.py
+++ b/posthog/personhog_client/test_converters.py
@@ -61,10 +61,11 @@ class TestProtoGroupTypeMappingToDict:
},
),
(
- "proto_defaults_become_none",
+ "proto_defaults_keep_group_type_string",
{"group_type_index": 1},
{
- "group_type": None,
+ # group_type is NOT NULL in the DB, so it stays a string (mirrors the ORM .values() path)
+ "group_type": "",
"group_type_index": 1,
"name_singular": None,
"name_plural": None,
@@ -74,7 +75,7 @@ class TestProtoGroupTypeMappingToDict:
},
),
(
- "empty_strings_become_none",
+ "empty_optional_strings_become_none",
{
"group_type": "",
"group_type_index": 2,
@@ -85,7 +86,7 @@ class TestProtoGroupTypeMappingToDict:
"created_at": 0,
},
{
- "group_type": None,
+ "group_type": "",
"group_type_index": 2,
"name_singular": None,
"name_plural": None,