: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(alerts): prevent currency symbol doubling when prefix matches currency format (#68259)
Matt Puac20f7536c626
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex a8e2367c7147..c0b686da7e91 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -1383,7 +1383,7 @@ snapshots:components-playerinspector--with-logs-filter--dark:hash: v1.k794b7964.4a27837802248b94d5c146c18b6962bfc713ce40ec3da10a23d4fc89639cf794.PRcX4NksDqdhgKXU-BTlmrZ4mkRVcQIAlLsj5nbUq9Icomponents-playerinspector--with-logs-filter--light:- hash: v1.k794b7964.97c396a5d41b78e6f653cdcb59a7e59dce49c44d08a9c3903dd69324eb20fdd6.UcFWQBXiTFaua5umBEqB8d8UUCI6aLN4cXg2abaVyJ0+ hash: v1.k794b7964.92f552147017e8b361ea4c2eff62c087ce37fedfc44d40945ba40dbf12e01f08.KBu7dt9Qb1dmTqIGmFIKmCjktRGu8gAFQa0YzD86djAcomponents-playerinspector--with-logs-filter-upsell--dark:hash: v1.k794b7964.5e4afe863e34df7278c0dd092946adfd396ee778f0cd0a41e5e3f5e1771a9601.SBOdVp0jJnn1w2H4fMR-3Vf2ac00QSBFQjsl93AbcYAcomponents-playerinspector--with-logs-filter-upsell--light:diff --git a/frontend/src/scenes/insights/aggregationAxisFormat.ts b/frontend/src/scenes/insights/aggregationAxisFormat.tsindex 1c1793905886..7ca9e6d4171d 100644--- a/frontend/src/scenes/insights/aggregationAxisFormat.ts+++ b/frontend/src/scenes/insights/aggregationAxisFormat.ts@@ -91,7 +91,14 @@ export const formatAggregationAxisValue = (break}}- return `${aggregationAxisPrefix || ''}${formattedValue}${aggregationAxisPostfix || ''}`+ // Currency format already embeds the symbol, so a matching prefix ("$" + "$94.02") would double it.+ const effectivePrefix =+ aggregationAxisFormat === 'currency' &&+ aggregationAxisPrefix &&+ formattedValue.startsWith(aggregationAxisPrefix)+ ? ''+ : aggregationAxisPrefix || ''+ return `${effectivePrefix}${formattedValue}${aggregationAxisPostfix || ''}`}export const formatPercentStackAxisValue = (diff --git a/frontend/src/scenes/insights/aggregationAxisFormats.test.ts b/frontend/src/scenes/insights/aggregationAxisFormats.test.tsindex cf26ee535320..f645bb146bf4 100644--- a/frontend/src/scenes/insights/aggregationAxisFormats.test.ts+++ b/frontend/src/scenes/insights/aggregationAxisFormats.test.ts@@ -51,6 +51,29 @@ describe('formatAggregationAxisValue', () => {currency: 'EUR' as CurrencyCode,expected: '€3,940.00',},+ {+ candidate: 94.02,+ filters: { aggregationAxisFormat: 'currency', aggregationAxisPrefix: '$' },+ currency: 'USD' as CurrencyCode,+ expected: '$94.02',+ },+ {+ candidate: 94.02,+ filters: { aggregationAxisFormat: 'currency', aggregationAxisPrefix: '€' },+ currency: 'EUR' as CurrencyCode,+ expected: '€94.02',+ },+ {+ candidate: 94.02,+ filters: { aggregationAxisFormat: 'currency', aggregationAxisPrefix: 'USD ' },+ currency: 'USD' as CurrencyCode,+ expected: 'USD $94.02',+ },+ {+ candidate: 1000,+ filters: { aggregationAxisFormat: 'numeric', aggregationAxisPrefix: '1' },+ expected: '11,000',+ },{ candidate: 0.8709423, filters: {}, expected: '0.87' },{ candidate: 0.8709423, filters: { decimal_places: 2 }, expected: '0.87' },{ candidate: 0.8709423, filters: { decimal_places: 3 }, expected: '0.871' },diff --git a/products/alerts/backend/evaluation/formatting.py b/products/alerts/backend/evaluation/formatting.pyindex bea7a096ee44..4709d8b730a1 100644--- a/products/alerts/backend/evaluation/formatting.py+++ b/products/alerts/backend/evaluation/formatting.py@@ -107,7 +107,13 @@ def format_aggregation_value(case _: # NUMERIC or unsetformatted = _human_friendly_number(value, decimal_places, min_decimal_places)- return f"{prefix or ''}{formatted}{postfix or ''}"+ # Currency format already embeds the symbol, so a matching prefix ("$" + "$94.02") would double it.+ effective_prefix = (+ ""+ if (axis_format == AggregationAxisFormat.CURRENCY and prefix and formatted.startswith(prefix))+ else (prefix or "")+ )+ return f"{effective_prefix}{formatted}{postfix or ''}"def _clamp_decimal_places(value: float | None, fallback: int) -> int:diff --git a/products/alerts/backend/evaluation/test/test_formatting.py b/products/alerts/backend/evaluation/test/test_formatting.pyindex 644230fe2ed0..e28bbf02319a 100644--- a/products/alerts/backend/evaluation/test/test_formatting.py+++ b/products/alerts/backend/evaluation/test/test_formatting.py@@ -27,6 +27,11 @@ A = AggregationAxisFormat(50.0, {"axis_format": A.CURRENCY, "currency": None}, "$50.00"),# prefix/postfix wrap the formatted value verbatim (they carry their own spacing)(1234.0, {"prefix": "$", "postfix": " reqs"}, "$1,234 reqs"),+ (94.02, {"axis_format": A.CURRENCY, "currency": "USD", "prefix": "$"}, "$94.02"),+ (10.0, {"axis_format": A.CURRENCY, "currency": "EUR", "prefix": "€"}, "€10.00"),+ (94.02, {"axis_format": A.CURRENCY, "currency": "USD", "prefix": "USD "}, "USD $94.02"),+ # a non-currency prefix that shares a leading char with the value is kept, not dropped+ (1000.0, {"prefix": "1"}, "11,000"),# duration: seconds humanized; negative (relative differences) and zero handled(72.0, {"axis_format": A.DURATION}, "1m 12s"),(0.0, {"axis_format": A.DURATION}, "0s"),