mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Simplified imports from django.db and django.contrib.gis.db.
This commit is contained in:
committed by
Mariusz Felisiak
parent
469bf2db15
commit
335c9c94ac
@@ -10,12 +10,12 @@ import pytz
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import DEFAULT_DB_ALIAS
|
||||
from django.db import DEFAULT_DB_ALIAS, DatabaseError
|
||||
from django.db.backends import utils
|
||||
from django.db.backends.base.validation import BaseDatabaseValidation
|
||||
from django.db.backends.signals import connection_created
|
||||
from django.db.transaction import TransactionManagementError
|
||||
from django.db.utils import DatabaseError, DatabaseErrorWrapper
|
||||
from django.db.utils import DatabaseErrorWrapper
|
||||
from django.utils import timezone
|
||||
from django.utils.asyncio import async_unsafe
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db.utils import ProgrammingError
|
||||
from django.db import ProgrammingError
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ MySQL database backend for Django.
|
||||
Requires mysqlclient: https://pypi.org/project/mysqlclient/
|
||||
"""
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import utils
|
||||
from django.db import IntegrityError
|
||||
from django.db.backends import utils as backend_utils
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.utils.asyncio import async_unsafe
|
||||
@@ -75,7 +75,7 @@ class CursorWrapper:
|
||||
# Map some error codes to IntegrityError, since they seem to be
|
||||
# misclassified and Django would prefer the more logical place.
|
||||
if e.args[0] in self.codes_for_integrityerror:
|
||||
raise utils.IntegrityError(*tuple(e.args))
|
||||
raise IntegrityError(*tuple(e.args))
|
||||
raise
|
||||
|
||||
def executemany(self, query, args):
|
||||
@@ -85,7 +85,7 @@ class CursorWrapper:
|
||||
# Map some error codes to IntegrityError, since they seem to be
|
||||
# misclassified and Django would prefer the more logical place.
|
||||
if e.args[0] in self.codes_for_integrityerror:
|
||||
raise utils.IntegrityError(*tuple(e.args))
|
||||
raise IntegrityError(*tuple(e.args))
|
||||
raise
|
||||
|
||||
def __getattr__(self, attr):
|
||||
@@ -314,7 +314,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
)
|
||||
)
|
||||
for bad_row in cursor.fetchall():
|
||||
raise utils.IntegrityError(
|
||||
raise IntegrityError(
|
||||
"The row in table '%s' with primary key '%s' has an invalid "
|
||||
"foreign key: %s.%s contains a value '%s' that does not "
|
||||
"have a corresponding value in %s.%s."
|
||||
|
||||
@@ -6,7 +6,7 @@ from MySQLdb.constants import FIELD_TYPE
|
||||
from django.db.backends.base.introspection import (
|
||||
BaseDatabaseIntrospection, FieldInfo as BaseFieldInfo, TableInfo,
|
||||
)
|
||||
from django.db.models.indexes import Index
|
||||
from django.db.models import Index
|
||||
from django.utils.datastructures import OrderedSet
|
||||
|
||||
FieldInfo = namedtuple('FieldInfo', BaseFieldInfo._fields + ('extra', 'is_unsigned'))
|
||||
|
||||
@@ -11,7 +11,7 @@ from contextlib import contextmanager
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import utils
|
||||
from django.db import IntegrityError
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.utils.asyncio import async_unsafe
|
||||
from django.utils.encoding import force_bytes, force_str
|
||||
@@ -74,7 +74,7 @@ def wrap_oracle_errors():
|
||||
# Convert that case to Django's IntegrityError exception.
|
||||
x = e.args[0]
|
||||
if hasattr(x, 'code') and hasattr(x, 'message') and x.code == 2091 and 'ORA-02291' in x.message:
|
||||
raise utils.IntegrityError(*tuple(e.args))
|
||||
raise IntegrityError(*tuple(e.args))
|
||||
raise
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import sys
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import DatabaseError
|
||||
from django.db.backends.base.creation import BaseDatabaseCreation
|
||||
from django.db.utils import DatabaseError
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.db import InterfaceError
|
||||
from django.db.backends.base.features import BaseDatabaseFeatures
|
||||
from django.db.utils import InterfaceError
|
||||
|
||||
|
||||
class DatabaseFeatures(BaseDatabaseFeatures):
|
||||
|
||||
@@ -3,11 +3,12 @@ import uuid
|
||||
from functools import lru_cache
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import DatabaseError
|
||||
from django.db.backends.base.operations import BaseDatabaseOperations
|
||||
from django.db.backends.utils import strip_quotes, truncate_name
|
||||
from django.db.models.expressions import Exists, ExpressionWrapper, RawSQL
|
||||
from django.db.models import AutoField, Exists, ExpressionWrapper
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.db.models.sql.where import WhereNode
|
||||
from django.db.utils import DatabaseError
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_bytes, force_str
|
||||
from django.utils.functional import cached_property
|
||||
@@ -466,12 +467,11 @@ END;
|
||||
return sql
|
||||
|
||||
def sequence_reset_sql(self, style, model_list):
|
||||
from django.db import models
|
||||
output = []
|
||||
query = self._sequence_reset_sql
|
||||
for model in model_list:
|
||||
for f in model._meta.local_fields:
|
||||
if isinstance(f, models.AutoField):
|
||||
if isinstance(f, AutoField):
|
||||
no_autofield_sequence_name = self._get_no_autofield_sequence_name(model._meta.db_table)
|
||||
table = self.quote_name(model._meta.db_table)
|
||||
column = self.quote_name(f.column)
|
||||
|
||||
@@ -2,8 +2,8 @@ import copy
|
||||
import datetime
|
||||
import re
|
||||
|
||||
from django.db import DatabaseError
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.db.utils import DatabaseError
|
||||
|
||||
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
|
||||
@@ -10,12 +10,11 @@ import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import connections
|
||||
from django.db import DatabaseError as WrappedDatabaseError, connections
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.db.backends.utils import (
|
||||
CursorDebugWrapper as BaseCursorDebugWrapper,
|
||||
)
|
||||
from django.db.utils import DatabaseError as WrappedDatabaseError
|
||||
from django.utils.asyncio import async_unsafe
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.safestring import SafeString
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import operator
|
||||
|
||||
from django.db import InterfaceError
|
||||
from django.db.backends.base.features import BaseDatabaseFeatures
|
||||
from django.db.utils import InterfaceError
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.db.backends.base.introspection import (
|
||||
BaseDatabaseIntrospection, FieldInfo, TableInfo,
|
||||
)
|
||||
from django.db.models.indexes import Index
|
||||
from django.db.models import Index
|
||||
|
||||
|
||||
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
|
||||
@@ -16,7 +16,7 @@ from sqlite3 import dbapi2 as Database
|
||||
import pytz
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import utils
|
||||
from django.db import IntegrityError
|
||||
from django.db.backends import utils as backend_utils
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.utils import timezone
|
||||
@@ -328,7 +328,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
),
|
||||
(rowid,),
|
||||
).fetchone()
|
||||
raise utils.IntegrityError(
|
||||
raise IntegrityError(
|
||||
"The row in table '%s' with primary key '%s' has an "
|
||||
"invalid foreign key: %s.%s contains a value '%s' that "
|
||||
"does not have a corresponding value in %s.%s." % (
|
||||
@@ -360,7 +360,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
)
|
||||
)
|
||||
for bad_row in cursor.fetchall():
|
||||
raise utils.IntegrityError(
|
||||
raise IntegrityError(
|
||||
"The row in table '%s' with primary key '%s' has an "
|
||||
"invalid foreign key: %s.%s contains a value '%s' that "
|
||||
"does not have a corresponding value in %s.%s." % (
|
||||
|
||||
@@ -6,7 +6,7 @@ import sqlparse
|
||||
from django.db.backends.base.introspection import (
|
||||
BaseDatabaseIntrospection, FieldInfo as BaseFieldInfo, TableInfo,
|
||||
)
|
||||
from django.db.models.indexes import Index
|
||||
from django.db.models import Index
|
||||
from django.utils.regex_helper import _lazy_re_compile
|
||||
|
||||
FieldInfo = namedtuple('FieldInfo', BaseFieldInfo._fields + ('pk',))
|
||||
|
||||
@@ -6,9 +6,8 @@ from itertools import chain
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import FieldError
|
||||
from django.db import utils
|
||||
from django.db import DatabaseError, NotSupportedError, models
|
||||
from django.db.backends.base.operations import BaseDatabaseOperations
|
||||
from django.db.models import aggregates, fields
|
||||
from django.db.models.expressions import Col
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_date, parse_datetime, parse_time
|
||||
@@ -40,8 +39,8 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||
return len(objs)
|
||||
|
||||
def check_expression_support(self, expression):
|
||||
bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
|
||||
bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
|
||||
bad_fields = (models.DateField, models.DateTimeField, models.TimeField)
|
||||
bad_aggregates = (models.Sum, models.Avg, models.Variance, models.StdDev)
|
||||
if isinstance(expression, bad_aggregates):
|
||||
for expr in expression.get_source_expressions():
|
||||
try:
|
||||
@@ -52,13 +51,13 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||
pass
|
||||
else:
|
||||
if isinstance(output_field, bad_fields):
|
||||
raise utils.NotSupportedError(
|
||||
raise NotSupportedError(
|
||||
'You cannot use Sum, Avg, StdDev, and Variance '
|
||||
'aggregations on date/time fields in sqlite3 '
|
||||
'since date/time is saved as text.'
|
||||
)
|
||||
if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
|
||||
raise utils.NotSupportedError(
|
||||
if isinstance(expression, models.Aggregate) and len(expression.source_expressions) > 1:
|
||||
raise NotSupportedError(
|
||||
"SQLite doesn't support DISTINCT on aggregate functions "
|
||||
"accepting multiple arguments."
|
||||
)
|
||||
@@ -313,7 +312,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||
|
||||
def combine_duration_expression(self, connector, sub_expressions):
|
||||
if connector not in ['+', '-']:
|
||||
raise utils.DatabaseError('Invalid connector for timedelta: %s.' % connector)
|
||||
raise DatabaseError('Invalid connector for timedelta: %s.' % connector)
|
||||
fn_params = ["'%s'" % connector] + sub_expressions
|
||||
if len(fn_params) > 3:
|
||||
raise ValueError('Too many params for timedelta operations.')
|
||||
|
||||
@@ -2,12 +2,12 @@ import copy
|
||||
from decimal import Decimal
|
||||
|
||||
from django.apps.registry import Apps
|
||||
from django.db import NotSupportedError
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.db.backends.ddl_references import Statement
|
||||
from django.db.backends.utils import strip_quotes
|
||||
from django.db.models import UniqueConstraint
|
||||
from django.db.transaction import atomic
|
||||
from django.db.utils import NotSupportedError
|
||||
|
||||
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
|
||||
@@ -6,7 +6,7 @@ import logging
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
|
||||
from django.db.utils import NotSupportedError
|
||||
from django.db import NotSupportedError
|
||||
|
||||
logger = logging.getLogger('django.db.backends')
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db.utils import DatabaseError
|
||||
from django.db import DatabaseError
|
||||
|
||||
|
||||
class AmbiguityError(Exception):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
from django.db.models.fields import NOT_PROVIDED
|
||||
from django.db.models import NOT_PROVIDED
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
from .base import Operation
|
||||
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
import sys
|
||||
|
||||
from django.apps import apps
|
||||
from django.db.models.fields import NOT_PROVIDED
|
||||
from django.db.models import NOT_PROVIDED
|
||||
from django.utils import timezone
|
||||
|
||||
from .loader import MigrationLoader
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from django.apps.registry import Apps
|
||||
from django.db import models
|
||||
from django.db.utils import DatabaseError
|
||||
from django.db import DatabaseError, models
|
||||
from django.utils.functional import classproperty
|
||||
from django.utils.timezone import now
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ from django.apps import AppConfig
|
||||
from django.apps.registry import Apps, apps as global_apps
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.db.models.fields.proxy import OrderWrt
|
||||
from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
|
||||
from django.db.models.options import DEFAULT_NAMES, normalize_together
|
||||
from django.db.models.utils import make_model_tuple
|
||||
@@ -406,7 +405,7 @@ class ModelState:
|
||||
for field in model._meta.local_fields:
|
||||
if getattr(field, "remote_field", None) and exclude_rels:
|
||||
continue
|
||||
if isinstance(field, OrderWrt):
|
||||
if isinstance(field, models.OrderWrt):
|
||||
continue
|
||||
name = field.name
|
||||
try:
|
||||
|
||||
@@ -12,7 +12,8 @@ from django.db.models.enums import * # NOQA
|
||||
from django.db.models.enums import __all__ as enums_all
|
||||
from django.db.models.expressions import (
|
||||
Case, Exists, Expression, ExpressionList, ExpressionWrapper, F, Func,
|
||||
OuterRef, RowRange, Subquery, Value, ValueRange, When, Window, WindowFrame,
|
||||
OrderBy, OuterRef, RowRange, Subquery, Value, ValueRange, When, Window,
|
||||
WindowFrame,
|
||||
)
|
||||
from django.db.models.fields import * # NOQA
|
||||
from django.db.models.fields import __all__ as fields_all
|
||||
@@ -22,16 +23,14 @@ from django.db.models.indexes import * # NOQA
|
||||
from django.db.models.indexes import __all__ as indexes_all
|
||||
from django.db.models.lookups import Lookup, Transform
|
||||
from django.db.models.manager import Manager
|
||||
from django.db.models.query import (
|
||||
Prefetch, Q, QuerySet, prefetch_related_objects,
|
||||
)
|
||||
from django.db.models.query_utils import FilteredRelation
|
||||
from django.db.models.query import Prefetch, QuerySet, prefetch_related_objects
|
||||
from django.db.models.query_utils import FilteredRelation, Q
|
||||
|
||||
# Imports that would create circular imports if sorted
|
||||
from django.db.models.base import DEFERRED, Model # isort:skip
|
||||
from django.db.models.fields.related import ( # isort:skip
|
||||
ForeignKey, ForeignObject, OneToOneField, ManyToManyField,
|
||||
ManyToOneRel, ManyToManyRel, OneToOneRel,
|
||||
ForeignObjectRel, ManyToOneRel, ManyToManyRel, OneToOneRel,
|
||||
)
|
||||
|
||||
|
||||
@@ -41,11 +40,12 @@ __all__ += [
|
||||
'CASCADE', 'DO_NOTHING', 'PROTECT', 'RESTRICT', 'SET', 'SET_DEFAULT',
|
||||
'SET_NULL', 'ProtectedError', 'RestrictedError',
|
||||
'Case', 'Exists', 'Expression', 'ExpressionList', 'ExpressionWrapper', 'F',
|
||||
'Func', 'OuterRef', 'RowRange', 'Subquery', 'Value', 'ValueRange', 'When',
|
||||
'Func', 'OrderBy', 'OuterRef', 'RowRange', 'Subquery', 'Value',
|
||||
'ValueRange', 'When',
|
||||
'Window', 'WindowFrame',
|
||||
'FileField', 'ImageField', 'OrderWrt', 'Lookup', 'Transform', 'Manager',
|
||||
'Prefetch', 'Q', 'QuerySet', 'prefetch_related_objects', 'DEFERRED', 'Model',
|
||||
'FilteredRelation',
|
||||
'ForeignKey', 'ForeignObject', 'OneToOneField', 'ManyToManyField',
|
||||
'ManyToOneRel', 'ManyToManyRel', 'OneToOneRel',
|
||||
'ForeignObjectRel', 'ManyToOneRel', 'ManyToManyRel', 'OneToOneRel',
|
||||
]
|
||||
|
||||
@@ -4,10 +4,9 @@ import inspect
|
||||
from decimal import Decimal
|
||||
|
||||
from django.core.exceptions import EmptyResultSet, FieldError
|
||||
from django.db import connection
|
||||
from django.db import NotSupportedError, connection
|
||||
from django.db.models import fields
|
||||
from django.db.models.query_utils import Q
|
||||
from django.db.utils import NotSupportedError
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.hashable import make_hashable
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from django.db import NotSupportedError
|
||||
from django.db.models.expressions import Func, Value
|
||||
from django.db.models.fields import IntegerField
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.db.models.lookups import Transform
|
||||
from django.db.utils import NotSupportedError
|
||||
|
||||
|
||||
class BytesToCharFieldConversionMixin:
|
||||
|
||||
@@ -7,9 +7,7 @@ from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
from django.db import connections
|
||||
from django.db.models import Manager
|
||||
from django.db.models.fields import AutoField
|
||||
from django.db.models.fields.proxy import OrderWrt
|
||||
from django.db.models import AutoField, Manager, OrderWrt
|
||||
from django.db.models.query_utils import PathInfo
|
||||
from django.utils.datastructures import ImmutableList, OrderedSet
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
@@ -12,19 +12,17 @@ from itertools import chain
|
||||
from django.conf import settings
|
||||
from django.core import exceptions
|
||||
from django.db import (
|
||||
DJANGO_VERSION_PICKLE_KEY, IntegrityError, connections, router,
|
||||
transaction,
|
||||
DJANGO_VERSION_PICKLE_KEY, IntegrityError, NotSupportedError, connections,
|
||||
router, transaction,
|
||||
)
|
||||
from django.db.models import DateField, DateTimeField, sql
|
||||
from django.db.models import AutoField, DateField, DateTimeField, sql
|
||||
from django.db.models.constants import LOOKUP_SEP
|
||||
from django.db.models.deletion import Collector
|
||||
from django.db.models.expressions import Case, Expression, F, Value, When
|
||||
from django.db.models.fields import AutoField
|
||||
from django.db.models.functions import Cast, Trunc
|
||||
from django.db.models.query_utils import FilteredRelation, Q
|
||||
from django.db.models.sql.constants import CURSOR, GET_ITERATOR_CHUNK_SIZE
|
||||
from django.db.models.utils import resolve_callables
|
||||
from django.db.utils import NotSupportedError
|
||||
from django.utils import timezone
|
||||
from django.utils.functional import cached_property, partition
|
||||
from django.utils.version import get_version
|
||||
|
||||
@@ -4,6 +4,7 @@ from functools import partial
|
||||
from itertools import chain
|
||||
|
||||
from django.core.exceptions import EmptyResultSet, FieldError
|
||||
from django.db import DatabaseError, NotSupportedError
|
||||
from django.db.models.constants import LOOKUP_SEP
|
||||
from django.db.models.expressions import OrderBy, Random, RawSQL, Ref, Value
|
||||
from django.db.models.functions import Cast
|
||||
@@ -13,7 +14,6 @@ from django.db.models.sql.constants import (
|
||||
)
|
||||
from django.db.models.sql.query import Query, get_order_dir
|
||||
from django.db.transaction import TransactionManagementError
|
||||
from django.db.utils import DatabaseError, NotSupportedError
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.hashable import make_hashable
|
||||
|
||||
|
||||
Reference in New Issue
Block a user