Skip to content

fix: elements chain not working#30267

Merged
aspicer merged 4 commits intomasterfrom
aspicer/elements_chain
Mar 21, 2025
Merged

fix: elements chain not working#30267
aspicer merged 4 commits intomasterfrom
aspicer/elements_chain

Conversation

@aspicer
Copy link
Contributor

@aspicer aspicer commented Mar 21, 2025

Problem

In Autocapture, we have an event property called $elements_chain
image

$elements_chain isn't a real property though, it's a field on events.

However, we don't treat it like such, so it causes the event property to be useless.
ifNull(notILike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$elements_chain'), ''), 'null'), '^"|"$', '')), '%div%'), 1)

Reported here:
https://posthoghelp.zendesk.com/agent/tickets/27104

Changes

Make it useful!

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Wrote a test.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR fixes the handling of $elements_chain property in Autocapture events by treating it as a direct column rather than a JSON property. Here are the key changes:

  • Modified property_to_expr in posthog/hogql/property.py to handle $elements_chain as a direct column on events table
  • Added test case in posthog/hogql_queries/test/test_events_query_runner.py to verify element chain filtering
  • Improves query performance by avoiding JSON extraction for elements_chain field
  • Fixes broken element chain filtering functionality reported in support ticket

The changes are focused and address a specific issue with element chain property handling in PostHog's event querying system.

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

runner = EventsQueryRunner(query=query, team=self.team)
response = runner.run()

self.assertEqual(len(response.results), 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Test only checks length of results. Consider verifying the actual content of the filtered results to ensure correct event was filtered out.

Suggested change
self.assertEqual(len(response.results), 1)
self.assertEqual(len(response.results), 1)
self.assertNotIn('div', response.results[0][0]['elements_chain'])

@aspicer aspicer requested a review from a team March 21, 2025 07:44
@aspicer aspicer enabled auto-merge (squash) March 21, 2025 09:11
@aspicer aspicer merged commit ba2c7c0 into master Mar 21, 2025
90 checks passed
@aspicer aspicer deleted the aspicer/elements_chain branch March 21, 2025 18:46
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