Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hogql): correctly parse breakdown values with quotes for funnels #21101

Merged
merged 8 commits into from
Mar 23, 2024

Conversation

thmsobrmlr
Copy link
Contributor

@thmsobrmlr thmsobrmlr commented Mar 22, 2024

Problem

Some HogQL funnel insights have been failing, as a breakdown value containing a single quote was parsed erroneously as ast.Field instead of the correct ast.Constant.

Edit: checked all occurances of parse_expr in funnels and added similar fixes.

Changes

Fixes it.

How did you test this code?

Added a test and verified with a local insight

@thmsobrmlr thmsobrmlr removed the request for review from a team March 22, 2024 15:51
@thmsobrmlr thmsobrmlr marked this pull request as draft March 22, 2024 15:51
Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I'd actually suggest taking it a step further some other time before release, and moving as much python string interpolation in parse_expr into placeholders as possible. This could avoid a bunch of random errors down the line.

Also some mypy troubles.

posthog/hogql_queries/insights/funnels/base.py Outdated Show resolved Hide resolved
return [parse_expr(f"if(has({breakdown_values}, prop), prop, {other_aggregation}) as prop")]
return [
parse_expr(
f"if(has({{breakdown_values}}, prop), prop, {other_aggregation}) as prop",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more things we can move to placeholders overall, the better. Could other_aggregation also go? It's equally a constant. Same with possibly self._get_breakdown_prop() above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jup, I agree. Would be great to even have a lint rule warning about f-strings with parse_expr.

For now I went over all usages of parse_expr in funnels and checked that the interpolated strings work as expected e.g. there are a lot of places where some number is interpolated latest_{i} and i is validated via pydantic.

if normalize_url:
regex = "[\\\\/?#]*$"
expr = parse_expr(
f"if( empty( replaceRegexpOne({{breakdown_value}}, '{regex}', '') ), '/', replaceRegexpOne({{breakdown_value}}, '{regex}', ''))",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regex could also be passed in through a placeholder

@thmsobrmlr thmsobrmlr marked this pull request as ready for review March 22, 2024 22:39
@thmsobrmlr thmsobrmlr merged commit bb04a18 into master Mar 23, 2024
88 checks passed
@thmsobrmlr thmsobrmlr deleted the fix-hogql-funnels-breakdown-parsing branch March 23, 2024 09:29
Copy link

sentry-io bot commented Apr 3, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ CHQueryErrorQueryWasCancelled: Code: 394. /api/projects/{parent_lookup_team_id}/query/ View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants