summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Dollinger <emulbreh@googlemail.com>2016-05-25 21:00:20 +0200
committerTim Graham <timograham@gmail.com>2016-08-08 10:43:34 -0400
commit46509cf13dbf049f75077981c29ef2c60b5a96ab (patch)
tree7e9400fede5c49a2cb2efa666d8fc44d0752ad3c
parentc002a0d39f18694f5e8a07d86684fc793b063056 (diff)
Moved EmpytResultSet to django.core.exceptions.
This removes the need for some inner imports.
-rw-r--r--django/core/exceptions.py5
-rw-r--r--django/db/models/expressions.py3
-rw-r--r--django/db/models/lookups.py2
-rw-r--r--django/db/models/sql/__init__.py2
-rw-r--r--django/db/models/sql/compiler.py3
-rw-r--r--django/db/models/sql/datastructures.py6
-rw-r--r--django/db/models/sql/where.py2
-rw-r--r--docs/ref/exceptions.txt13
-rw-r--r--tests/queries/tests.py3
9 files changed, 26 insertions, 13 deletions
diff --git a/django/core/exceptions.py b/django/core/exceptions.py
index 5b125e6fd5..002631bbbd 100644
--- a/django/core/exceptions.py
+++ b/django/core/exceptions.py
@@ -187,3 +187,8 @@ class ValidationError(Exception):
def __repr__(self):
return 'ValidationError(%s)' % self
+
+
+class EmptyResultSet(Exception):
+ """A database query predicate is impossible."""
+ pass
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
index 8e84be68cf..ce685203ea 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -1,7 +1,7 @@
import copy
import datetime
-from django.core.exceptions import FieldError
+from django.core.exceptions import EmptyResultSet, FieldError
from django.db.backends import utils as backend_utils
from django.db.models import fields
from django.db.models.query_utils import Q
@@ -836,7 +836,6 @@ class Case(Expression):
return c
def as_sql(self, compiler, connection, template=None, case_joiner=None, **extra_context):
- from django.db.models.sql.datastructures import EmptyResultSet
connection.ops.check_expression_support(self)
if not self.cases:
return compiler.compile(self.default)
diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
index cc02e2f6ff..4f10458c4c 100644
--- a/django/db/models/lookups.py
+++ b/django/db/models/lookups.py
@@ -2,6 +2,7 @@ import math
import warnings
from copy import copy
+from django.core.exceptions import EmptyResultSet
from django.db.models.expressions import Func, Value
from django.db.models.fields import DateTimeField, Field, IntegerField
from django.db.models.query_utils import RegisterLookupMixin
@@ -276,7 +277,6 @@ class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
rhs = self.rhs
if not rhs:
- from django.db.models.sql.datastructures import EmptyResultSet
raise EmptyResultSet
# rhs should be an iterable; use batch_process_rhs() to
diff --git a/django/db/models/sql/__init__.py b/django/db/models/sql/__init__.py
index 80c12584fd..31f45eb90d 100644
--- a/django/db/models/sql/__init__.py
+++ b/django/db/models/sql/__init__.py
@@ -1,4 +1,4 @@
-from django.db.models.sql.datastructures import EmptyResultSet
+from django.core.exceptions import EmptyResultSet
from django.db.models.sql.query import * # NOQA
from django.db.models.sql.subqueries import * # NOQA
from django.db.models.sql.where import AND, OR
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 0b7f9e20cb..cedb140143 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -1,14 +1,13 @@
import re
from itertools import chain
-from django.core.exceptions import FieldError
+from django.core.exceptions import EmptyResultSet, FieldError
from django.db.models.constants import LOOKUP_SEP
from django.db.models.expressions import OrderBy, Random, RawSQL, Ref
from django.db.models.query_utils import QueryWrapper, select_related_descend
from django.db.models.sql.constants import (
CURSOR, GET_ITERATOR_CHUNK_SIZE, MULTI, NO_RESULTS, ORDER_DIR, SINGLE,
)
-from django.db.models.sql.datastructures import EmptyResultSet
from django.db.models.sql.query import Query, get_order_dir
from django.db.transaction import TransactionManagementError
from django.db.utils import DatabaseError
diff --git a/django/db/models/sql/datastructures.py b/django/db/models/sql/datastructures.py
index 42f2d8790d..02e4f930e1 100644
--- a/django/db/models/sql/datastructures.py
+++ b/django/db/models/sql/datastructures.py
@@ -2,13 +2,11 @@
Useful auxiliary data structures for query construction. Not useful outside
the SQL domain.
"""
+# for backwards-compatibility in Django 1.11
+from django.core.exceptions import EmptyResultSet # NOQA: F401
from django.db.models.sql.constants import INNER, LOUTER
-class EmptyResultSet(Exception):
- pass
-
-
class MultiJoin(Exception):
"""
Used by join construction code to indicate the point at which a
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index 9836da8735..c70d34f94f 100644
--- a/django/db/models/sql/where.py
+++ b/django/db/models/sql/where.py
@@ -2,7 +2,7 @@
Code to manage the creation and SQL rendering of 'where' constraints.
"""
-from django.db.models.sql.datastructures import EmptyResultSet
+from django.core.exceptions import EmptyResultSet
from django.utils import tree
from django.utils.functional import cached_property
diff --git a/docs/ref/exceptions.txt b/docs/ref/exceptions.txt
index c222010172..8c05aca977 100644
--- a/docs/ref/exceptions.txt
+++ b/docs/ref/exceptions.txt
@@ -24,6 +24,19 @@ Django core exception classes are defined in ``django.core.exceptions``.
See :meth:`~django.db.models.query.QuerySet.get()` for further information
on :exc:`ObjectDoesNotExist` and :exc:`~django.db.models.Model.DoesNotExist`.
+``EmptyResultSet``
+------------------
+
+.. exception:: EmptyResultSet
+
+ ``EmptyResultSet`` may be raised during query generation if a query won't
+ return any results. Most Django projects won't encounter this exception,
+ but it might be useful for implementing custom lookups and expressions.
+
+ .. versionchanged:: 1.11
+
+ In older versions, it's only importable from ``django.db.models.sql``.
+
``FieldDoesNotExist``
---------------------
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index fdfd1b5725..a82f59e231 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -6,11 +6,10 @@ import unittest
from collections import OrderedDict
from operator import attrgetter
-from django.core.exceptions import FieldError
+from django.core.exceptions import EmptyResultSet, FieldError
from django.db import DEFAULT_DB_ALIAS, connection
from django.db.models import Count, F, Q
from django.db.models.sql.constants import LOUTER
-from django.db.models.sql.datastructures import EmptyResultSet
from django.db.models.sql.where import NothingNode, WhereNode
from django.test import TestCase, skipUnlessDBFeature
from django.test.utils import CaptureQueriesContext