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

Updated deprecated InvalidQuery Class #35

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Installation
------------
To use, first install (pypi package coming soon)::

pip install -e git+https://github.com/groveco/django-segments#egg=segments
pip install -e git+https://github.com/groveco/django-segments#egg=django-segments

Then add the following to your settings.py::

Expand Down
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 FieldDoesNotExist

from segments import app_settings

Expand Down Expand Up @@ -233,7 +233,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 FieldDoesNotExist

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 FieldDoesNotExist
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 FieldDoesNotExist:
raise SegmentExecutionError(
"SQL definition must include the primary key of the %s model"
% settings.AUTH_USER_MODEL
Expand Down