Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(api): profile property wildcards in charts match again

Carl-Gerhard Lindesvärd83b781ac8751
diff --git a/packages/core/src/modules/chart/src/field-resolution.ts b/packages/core/src/modules/chart/src/field-resolution.ts
index 1ec1e5617..ab4a1f8c8 100644
--- a/packages/core/src/modules/chart/src/field-resolution.ts
+++ b/packages/core/src/modules/chart/src/field-resolution.ts
@@ -305,7 +305,7 @@ export function transformPropertyKey(property: string) {
if (property.includes('*')) {
return property
- .replace(/^properties\./, '')
+ .replace(new RegExp(`^${match}\\.`), '')
.replace('.*.', '.%.')
.replace(/\[\*\]$/, '.%')
.replace(/\[\*\].?/, '.%.');
diff --git a/packages/core/src/modules/chart/src/sql.test.ts b/packages/core/src/modules/chart/src/sql.test.ts
index feb3d6222..3c93c5d6d 100644
--- a/packages/core/src/modules/chart/src/sql.test.ts
+++ b/packages/core/src/modules/chart/src/sql.test.ts
@@ -489,6 +489,9 @@ describe('profile-property narrowing', () => {
expect(text).toContain(
'argMax(properties, last_seen_at) as "profile.properties"'
);
+ // The pattern is a key inside the map, so the map prefix must be gone.
+ expect(text).toContain("'experiments.%.name'");
+ expect(text).not.toContain('profile.properties.experiments');
});
it('never narrows identifier-unsafe keys (backtick falls back to the Map)', async () => {
diff --git a/packages/core/src/modules/chart/src/sql.versions.test.ts b/packages/core/src/modules/chart/src/sql.versions.test.ts
index 685020d36..6f41499a5 100644
--- a/packages/core/src/modules/chart/src/sql.versions.test.ts
+++ b/packages/core/src/modules/chart/src/sql.versions.test.ts
@@ -169,7 +169,7 @@ describe('aggregate and series charts', () => {
'argMax(properties, last_seen_at) as "profile.properties"'
);
const result = await rows(statement);
- expect(countsBy(result, 'label_0')).toEqual({ screen_view: 5 });
+ expect(countsBy(result, 'label_1')).toEqual({ 'one-page': 3, '': 2 });
});
it('series totals agree with the aggregate', async () => {