-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Clearer error messages when editing actions #7359
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
from posthog.exceptions import EstimatedQueryExecutionTimeTooLong | ||
|
||
|
||
class CHQueryErrorCannotCompileRegexp(ServerException): | ||
pass | ||
|
||
|
||
def wrap_query_error(err: Exception) -> Exception: | ||
"Beautifies clickhouse client errors, using custom error classes for every code" | ||
if not isinstance(err, ServerException): | ||
|
@@ -17,6 +21,9 @@ def wrap_query_error(err: Exception) -> Exception: | |
|
||
# :TRICKY: Return a custom class for every code by looking up the short name and creating a class dynamically. | ||
if hasattr(err, "code"): | ||
if err.code == 427: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, this is the error coming from CH, whose name is |
||
return CHQueryErrorCannotCompileRegexp(err.message, code=err.code) | ||
|
||
name = CLICKHOUSE_ERROR_CODE_LOOKUP.get(err.code, "UNKNOWN") | ||
name = f"CHQueryError{name.replace('_', ' ').title().replace(' ', '')}" | ||
return type(name, (ServerException,), {})(err.message, code=err.code) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,13 @@ | |
|
||
from rest_framework import serializers | ||
from rest_framework.decorators import action | ||
from rest_framework.exceptions import ValidationError | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
from rest_framework_csv import renderers as csvrenderers | ||
|
||
from ee.clickhouse.client import sync_execute | ||
from ee.clickhouse.errors import CHQueryErrorCannotCompileRegexp | ||
from ee.clickhouse.models.action import format_action_filter | ||
from ee.clickhouse.queries.trends.person import TrendsPersonQuery | ||
from ee.clickhouse.sql.person import INSERT_COHORT_ALL_PEOPLE_THROUGH_PERSON_ID, PERSON_STATIC_COHORT_TABLE | ||
|
@@ -90,10 +92,13 @@ def count(self, request: Request, **kwargs) -> Response: # type: ignore | |
if query == "": | ||
return Response({"count": 0}) | ||
|
||
results = sync_execute( | ||
"SELECT count(1) FROM events WHERE team_id = %(team_id)s AND {}".format(query), | ||
{"team_id": action.team_id, **params}, | ||
) | ||
try: | ||
results = sync_execute( | ||
"SELECT count(1) FROM events WHERE team_id = %(team_id)s AND {}".format(query), | ||
{"team_id": action.team_id, **params}, | ||
) | ||
except CHQueryErrorCannotCompileRegexp: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to comment above, but why do we raise a Regexp compile error here? Is the only error that happen here related to a regex error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There can be several errors when querying CH (see the file above where I define this for the rest of them - all 500 of them), and this on is specific to the user input being provided for selectors / regexes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes |
||
raise ValidationError("Invalid filters for action count") | ||
neilkakkar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Response({"count": results[0][0]}) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We seem to be using this for multiple cases, not sure if the name reflects the right use for this. I would also suggest adding a useful default
code
&message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically for capturing the error CH sends to us. So, using the same name as the CH error code, to prevent confusion.
The error message we raise is
ValidationError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's always a
code
andmessage
generated from CH, so we shouldn't need to supply even a default one ourselves.