Moved EmpytResultSet to django.core.exceptions.
This removes the need for some inner imports.
This commit is contained in:
parent
c002a0d39f
commit
46509cf13d
|
@ -187,3 +187,8 @@ class ValidationError(Exception):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'ValidationError(%s)' % self
|
return 'ValidationError(%s)' % self
|
||||||
|
|
||||||
|
|
||||||
|
class EmptyResultSet(Exception):
|
||||||
|
"""A database query predicate is impossible."""
|
||||||
|
pass
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
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.backends import utils as backend_utils
|
||||||
from django.db.models import fields
|
from django.db.models import fields
|
||||||
from django.db.models.query_utils import Q
|
from django.db.models.query_utils import Q
|
||||||
|
@ -836,7 +836,6 @@ class Case(Expression):
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def as_sql(self, compiler, connection, template=None, case_joiner=None, **extra_context):
|
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)
|
connection.ops.check_expression_support(self)
|
||||||
if not self.cases:
|
if not self.cases:
|
||||||
return compiler.compile(self.default)
|
return compiler.compile(self.default)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import math
|
||||||
import warnings
|
import warnings
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
|
from django.core.exceptions import EmptyResultSet
|
||||||
from django.db.models.expressions import Func, Value
|
from django.db.models.expressions import Func, Value
|
||||||
from django.db.models.fields import DateTimeField, Field, IntegerField
|
from django.db.models.fields import DateTimeField, Field, IntegerField
|
||||||
from django.db.models.query_utils import RegisterLookupMixin
|
from django.db.models.query_utils import RegisterLookupMixin
|
||||||
|
@ -276,7 +277,6 @@ class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
|
||||||
rhs = self.rhs
|
rhs = self.rhs
|
||||||
|
|
||||||
if not rhs:
|
if not rhs:
|
||||||
from django.db.models.sql.datastructures import EmptyResultSet
|
|
||||||
raise EmptyResultSet
|
raise EmptyResultSet
|
||||||
|
|
||||||
# rhs should be an iterable; use batch_process_rhs() to
|
# rhs should be an iterable; use batch_process_rhs() to
|
||||||
|
|
|
@ -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.query import * # NOQA
|
||||||
from django.db.models.sql.subqueries import * # NOQA
|
from django.db.models.sql.subqueries import * # NOQA
|
||||||
from django.db.models.sql.where import AND, OR
|
from django.db.models.sql.where import AND, OR
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import re
|
import re
|
||||||
from itertools import chain
|
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.constants import LOOKUP_SEP
|
||||||
from django.db.models.expressions import OrderBy, Random, RawSQL, Ref
|
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.query_utils import QueryWrapper, select_related_descend
|
||||||
from django.db.models.sql.constants import (
|
from django.db.models.sql.constants import (
|
||||||
CURSOR, GET_ITERATOR_CHUNK_SIZE, MULTI, NO_RESULTS, ORDER_DIR, SINGLE,
|
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.models.sql.query import Query, get_order_dir
|
||||||
from django.db.transaction import TransactionManagementError
|
from django.db.transaction import TransactionManagementError
|
||||||
from django.db.utils import DatabaseError
|
from django.db.utils import DatabaseError
|
||||||
|
|
|
@ -2,13 +2,11 @@
|
||||||
Useful auxiliary data structures for query construction. Not useful outside
|
Useful auxiliary data structures for query construction. Not useful outside
|
||||||
the SQL domain.
|
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
|
from django.db.models.sql.constants import INNER, LOUTER
|
||||||
|
|
||||||
|
|
||||||
class EmptyResultSet(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class MultiJoin(Exception):
|
class MultiJoin(Exception):
|
||||||
"""
|
"""
|
||||||
Used by join construction code to indicate the point at which a
|
Used by join construction code to indicate the point at which a
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Code to manage the creation and SQL rendering of 'where' constraints.
|
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 import tree
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
|
|
|
@ -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
|
See :meth:`~django.db.models.query.QuerySet.get()` for further information
|
||||||
on :exc:`ObjectDoesNotExist` and :exc:`~django.db.models.Model.DoesNotExist`.
|
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``
|
``FieldDoesNotExist``
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,10 @@ import unittest
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from operator import attrgetter
|
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 import DEFAULT_DB_ALIAS, connection
|
||||||
from django.db.models import Count, F, Q
|
from django.db.models import Count, F, Q
|
||||||
from django.db.models.sql.constants import LOUTER
|
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.db.models.sql.where import NothingNode, WhereNode
|
||||||
from django.test import TestCase, skipUnlessDBFeature
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.test.utils import CaptureQueriesContext
|
from django.test.utils import CaptureQueriesContext
|
||||||
|
|
Loading…
Reference in New Issue