Moved EmpytResultSet to django.core.exceptions.

This removes the need for some inner imports.
This commit is contained in:
Johannes Dollinger 2016-05-25 21:00:20 +02:00 committed by Tim Graham
parent c002a0d39f
commit 46509cf13d
9 changed files with 26 additions and 13 deletions

View File

@ -187,3 +187,8 @@ class ValidationError(Exception):
def __repr__(self):
return 'ValidationError(%s)' % self
class EmptyResultSet(Exception):
"""A database query predicate is impossible."""
pass

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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``
---------------------

View File

@ -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