Conversation
Contributor
There was a problem hiding this comment.
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_exprinposthog/hogql/property.pyto handle $elements_chain as a direct column on events table - Added test case in
posthog/hogql_queries/test/test_events_query_runner.pyto 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) |
Contributor
There was a problem hiding this comment.
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']) |
HamedMP
approved these changes
Mar 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In Autocapture, we have an event property called $elements_chain

$elements_chainisn'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.