fix(insights): coerce sortableSemver argument to string#58712
fix(insights): coerce sortableSemver argument to string#58712sampennington wants to merge 1 commit into
Conversation
sortableSemver inlines to extract(assumeNotNull({}), ...), a string
operation. When the comparison targets an event/person property that has
a Numeric PropertyDefinition, the property-types transform first coerces
the field to Float64, so extract() receives a Float64 and ClickHouse
fails with "Illegal type Float64 of argument of function extract"
(code 43).
Wrap the argument in toString() so the function always operates on a
string regardless of how the property was typed upstream.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
🎭 Playwright didn't run on this PR — your changes touch code that could affect E2E behavior, but Playwright is opt-in via label now to keep CI cost down. Add the Most PRs don't need this. Real regressions still get caught on master and fix-forward. |
Automated code reviewScope: One-line fix in Correctness — the fix is soundWrapping Test — verifies "no crash" but not the interesting pathThe chosen property value Verdict: Ship itThe production fix is correct, minimal, and well-targeted. The only gap is test strength — not a blocker. Automated review — posted on behalf of a code-reviewer agent. |
Problem
ClickHouse queries using a semver comparison operator against an event/person property that has a Numeric
PropertyDefinitionfail deterministically withIllegal type Float64 of argument of function extract(code 43).sortableSemverinlines toextract(assumeNotNull({}), ...)— a string operation. When the comparison targets a Numeric-typed property, the property-types transform first coerces the field toFloat64, soextract()receives aFloat64and ClickHouse rejects it.Part of an effort to reduce deterministic product-analytics query-builder failures — tracking dashboard: https://metabase.prod-us.posthog.dev/dashboard/207-product-analytics-insight-query-failures
Changes
Wrap the
sortableSemverargument intoString()so the function always operates on a string, regardless of how the property was typed upstream.How did you test this code?
I'm an agent. Added an executing HogQL test (
test_sortable_semver_on_numeric_property) that creates a NumericPropertyDefinitionand runs asortableSemVercomparison against it through ClickHouse. Verified the test fails onorigin/masterwith the exactcode 43error and passes with the fix. Ran the existingsortable_semvertest suite — all pass. No snapshot files referencesortableSemver.Publish to changelog?
no
🤖 Agent context
Agent-authored (Claude Code, Opus 4.7). Requires human review.
Root cause traced from a production failing query: the offending expression was
extract(assumeNotNull(accurateCastOrNull(..., 'Float64')), '(\d+(\.\d+)+)'). The Float64 cast comes from the property-types transform, not fromsortableSemveritself. Fix chosen at the function definition (posthog/hogql/functions/posthog.py) so it is robust to any upstream coercion rather than special-casing the property-types transform.