Skip to content
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

updating django package. #44

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions segments/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import redis

from django.db import connections
from django.db.models.query_utils import InvalidQuery
from django.core.exceptions import FieldError

from segments import app_settings

Expand Down Expand Up @@ -247,7 +247,7 @@ def execute_raw_user_query(self, sql):
Helper that returns an array containing a RawQuerySet of user ids and their total count.
"""
if sql is None or not isinstance(sql, str) or "select" not in sql.lower():
raise InvalidQuery
raise FieldError

with connections[app_settings.SEGMENTS_EXEC_CONNECTION].cursor() as cursor:
# Fetch the raw queryset of ids and count them
Expand Down
4 changes: 2 additions & 2 deletions segments/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from django.db import models, DatabaseError, OperationalError
from django.db.models.query_utils import InvalidQuery
from django.core.exceptions import FieldError
from django.conf import settings
from django.db.models import signals
from django.utils import timezone
Expand All @@ -27,7 +27,7 @@ def _wrapper(*args, **kwargs):
try:
return fn(*args, **kwargs)

except InvalidQuery:
except FieldError:
raise SegmentExecutionError(
"SQL definition must include the primary key of the %s model"
% settings.AUTH_USER_MODEL
Expand Down
4 changes: 2 additions & 2 deletions segments/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fakeredis
from django.db.models.query_utils import InvalidQuery
from django.core.exceptions import FieldError
from django.db.utils import OperationalError
from django.test import TestCase

Expand Down Expand Up @@ -96,7 +96,7 @@ def setUp(self):
def test_invalid_raw_user_query_raises_exception(self):
empty_queries = ["", None, 1, True, "any string that does not contain s.elect"]
for query in empty_queries:
with self.assertRaises(InvalidQuery, msg=f'Passed query: "{query}"') as cm:
with self.assertRaises(FieldError, msg=f'Passed query: "{query}"') as cm:
generator = self.helper.execute_raw_user_query(query)
for _ in generator:
pass
Expand Down
Loading