posthog icon indicating copy to clipboard operation
posthog copied to clipboard

refactor: improve error handling during ClickHouse query type mismatch while filtering session replays

Open namit-chandwani opened this issue 1 year ago • 2 comments

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_LOOKUP dictionary to include the TYPE_MISMATCH error with a descriptive message guiding users to correct the data types used in their filters.
    • posthog/session_recordings/session_recording_api.py:

      • Modified the list method within SessionRecordingViewSet to handle ExposedCHQueryError and ExposedHogQLError exceptions by raising a ValidationError with an appropriate error message and status code (400: Bad Request).
  • 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

namit-chandwani avatar Aug 09 '24 20:08 namit-chandwani

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

daibhin avatar Aug 12 '24 10:08 daibhin

Hey @daibhin @webjunkie, thanks for your insightful reviews!

I’ve pushed the required changes now. Please take a look when you get a chance

namit-chandwani avatar Aug 21 '24 15:08 namit-chandwani

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.

posthog-bot avatar Sep 05 '24 07:09 posthog-bot

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.

posthog-bot avatar Sep 16 '24 07:09 posthog-bot

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.

posthog-bot avatar Oct 01 '24 07:10 posthog-bot

This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.

posthog-bot avatar Oct 08 '24 07:10 posthog-bot