posthog
posthog copied to clipboard
refactor: improve error handling during ClickHouse query type mismatch while filtering session replays
Linked Issues
- Closes https://github.com/PostHog/posthog/issues/22716
Problem
- Filtering recordings by person properties fails when string inputs are used for numeric data types.
- Improving error handling for type mismatches in queries is essential to provide users with clear feedback and guidance for resolving such issues.
Changes
-
Backend:
-
posthog/errors.py:- Updated the
CLICKHOUSE_SPECIFIC_ERROR_LOOKUPdictionary to include theTYPE_MISMATCHerror with a descriptive message guiding users to correct the data types used in their filters.
- Updated the
-
posthog/session_recordings/session_recording_api.py:- Modified the
listmethod withinSessionRecordingViewSetto handleExposedCHQueryErrorandExposedHogQLErrorexceptions by raising aValidationErrorwith an appropriate error message and status code (400: Bad Request).
- Modified the
-
-
Frontend:
- No changes involved
These changes improve the robustness of error handling for ClickHouse queries, offering users clearer and more actionable error messages, especially in cases where there is a type mismatch in filter parameters during session recording queries.
Does this work well for both Cloud and self-hosted?
- Yes, it will work well for both Cloud and self-hosted PostHog instances.
How did you test this code?
-
Manual Testing:
- Manually tested filtering recordings by person properties using both correct and incorrect data types.
- Ensured that appropriate error messages are displayed when type mismatches occur.
-
Screen Recording of Testing:
https://github.com/user-attachments/assets/ca095ee1-0ff7-4eea-a402-9e0ccfbf2473
Type of change:
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [x] Refactoring (altering code without changing its external behaviour)
- [ ] Documentation change
- [ ] Other
Checklist:
- [x] Development completed
- [x] Comments added to code (wherever necessary)
- [ ] Documentation updated (if applicable)
- [ ] Added tests [Unit tests/Integration tests] (if required)
- [x] Tested changes locally
Follow-up tasks (if any):
- None
Additional Comments
- None
Looks good to me but going to tag the Product Analytics team for a review because they will be much more familiar with the HogQL code
Hey @daibhin @webjunkie, thanks for your insightful reviews!
I’ve pushed the required changes now. Please take a look when you get a chance
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week. If you want to permanentely keep it open, use the waiting label.
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week. If you want to permanentely keep it open, use the waiting label.
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week. If you want to permanentely keep it open, use the waiting label.
This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.