mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #23919 -- Replaced six.reraise by raise
This commit is contained in:
@@ -4,23 +4,21 @@ MySQL database backend for Django.
|
||||
Requires mysqlclient: https://pypi.python.org/pypi/mysqlclient/
|
||||
"""
|
||||
import re
|
||||
import sys
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import utils
|
||||
from django.db.backends import utils as backend_utils
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.utils import six
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.safestring import SafeBytes, SafeText
|
||||
|
||||
try:
|
||||
import MySQLdb as Database
|
||||
except ImportError as e:
|
||||
except ImportError as err:
|
||||
raise ImproperlyConfigured(
|
||||
'Error loading MySQLdb module: %s.\n'
|
||||
'Did you install mysqlclient or MySQL-python?' % e
|
||||
)
|
||||
'Error loading MySQLdb module.\n'
|
||||
'Did you install mysqlclient or MySQL-python?'
|
||||
) from err
|
||||
|
||||
from MySQLdb.constants import CLIENT, FIELD_TYPE # isort:skip
|
||||
from MySQLdb.converters import conversions # isort:skip
|
||||
@@ -88,7 +86,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:
|
||||
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
|
||||
raise utils.IntegrityError(*tuple(e.args))
|
||||
raise
|
||||
|
||||
def executemany(self, query, args):
|
||||
@@ -98,7 +96,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:
|
||||
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
|
||||
raise utils.IntegrityError(*tuple(e.args))
|
||||
raise
|
||||
|
||||
def __getattr__(self, attr):
|
||||
|
||||
@@ -7,13 +7,11 @@ import datetime
|
||||
import decimal
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import utils
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
@@ -261,7 +259,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
x = e.args[0]
|
||||
if hasattr(x, 'code') and hasattr(x, 'message') \
|
||||
and x.code == 2091 and 'ORA-02291' in x.message:
|
||||
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
|
||||
raise utils.IntegrityError(*tuple(e.args))
|
||||
raise
|
||||
|
||||
# Oracle doesn't support releasing savepoints. But we fake them when query
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import sys
|
||||
import warnings
|
||||
from collections import deque
|
||||
from functools import total_ordering
|
||||
|
||||
from django.db.migrations.state import ProjectState
|
||||
from django.utils import six
|
||||
from django.utils.datastructures import OrderedSet
|
||||
|
||||
from .exceptions import CircularDependencyError, NodeNotFoundError
|
||||
@@ -178,16 +176,12 @@ class MigrationGraph:
|
||||
replaced = set(replaced)
|
||||
try:
|
||||
replacement_node = self.node_map[replacement]
|
||||
except KeyError as exc:
|
||||
exc_value = NodeNotFoundError(
|
||||
except KeyError as err:
|
||||
raise NodeNotFoundError(
|
||||
"Unable to find replacement node %r. It was either never added"
|
||||
" to the migration graph, or has been removed." % (replacement, ),
|
||||
replacement
|
||||
)
|
||||
exc_value.__cause__ = exc
|
||||
if not hasattr(exc, '__traceback__'):
|
||||
exc.__traceback__ = sys.exc_info()[2]
|
||||
six.reraise(NodeNotFoundError, exc_value, sys.exc_info()[2])
|
||||
) from err
|
||||
for replaced_key in replaced:
|
||||
self.nodes.pop(replaced_key, None)
|
||||
replaced_node = self.node_map.pop(replaced_key, None)
|
||||
@@ -218,16 +212,12 @@ class MigrationGraph:
|
||||
self.nodes.pop(replacement, None)
|
||||
try:
|
||||
replacement_node = self.node_map.pop(replacement)
|
||||
except KeyError as exc:
|
||||
exc_value = NodeNotFoundError(
|
||||
except KeyError as err:
|
||||
raise NodeNotFoundError(
|
||||
"Unable to remove replacement node %r. It was either never added"
|
||||
" to the migration graph, or has been removed already." % (replacement, ),
|
||||
replacement
|
||||
)
|
||||
exc_value.__cause__ = exc
|
||||
if not hasattr(exc, '__traceback__'):
|
||||
exc.__traceback__ = sys.exc_info()[2]
|
||||
six.reraise(NodeNotFoundError, exc_value, sys.exc_info()[2])
|
||||
) from err
|
||||
replaced_nodes = set()
|
||||
replaced_nodes_parents = set()
|
||||
for key in replaced:
|
||||
|
||||
@@ -6,7 +6,6 @@ from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.db.migrations.graph import MigrationGraph
|
||||
from django.db.migrations.recorder import MigrationRecorder
|
||||
from django.utils import six
|
||||
|
||||
from .exceptions import (
|
||||
AmbiguityError, BadMigrationError, InconsistentMigrationHistory,
|
||||
@@ -256,7 +255,7 @@ class MigrationLoader:
|
||||
is_replaced = any(candidate in self.graph.nodes for candidate in candidates)
|
||||
if not is_replaced:
|
||||
tries = ', '.join('%s.%s' % c for c in candidates)
|
||||
exc_value = NodeNotFoundError(
|
||||
raise NodeNotFoundError(
|
||||
"Migration {0} depends on nonexistent node ('{1}', '{2}'). "
|
||||
"Django tried to replace migration {1}.{2} with any of [{3}] "
|
||||
"but wasn't able to because some of the replaced migrations "
|
||||
@@ -264,11 +263,7 @@ class MigrationLoader:
|
||||
exc.origin, exc.node[0], exc.node[1], tries
|
||||
),
|
||||
exc.node
|
||||
)
|
||||
exc_value.__cause__ = exc
|
||||
if not hasattr(exc, '__traceback__'):
|
||||
exc.__traceback__ = sys.exc_info()[2]
|
||||
six.reraise(NodeNotFoundError, exc_value, sys.exc_info()[2])
|
||||
) from exc
|
||||
raise exc
|
||||
|
||||
def check_consistent_history(self, connection):
|
||||
|
||||
@@ -21,7 +21,7 @@ from django.db.models.fields import AutoField
|
||||
from django.db.models.functions import Trunc
|
||||
from django.db.models.query_utils import InvalidQuery, Q
|
||||
from django.db.models.sql.constants import CURSOR
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.functional import cached_property, partition
|
||||
from django.utils.version import get_version
|
||||
|
||||
@@ -498,7 +498,7 @@ class QuerySet:
|
||||
return self.get(**lookup), False
|
||||
except self.model.DoesNotExist:
|
||||
pass
|
||||
six.reraise(*exc_info)
|
||||
raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
|
||||
|
||||
def _extract_model_params(self, defaults, **kwargs):
|
||||
"""
|
||||
|
||||
@@ -5,7 +5,6 @@ from threading import local
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.utils import six
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
@@ -90,7 +89,7 @@ class DatabaseErrorWrapper:
|
||||
# the connection unusable.
|
||||
if dj_exc_type not in (DataError, IntegrityError):
|
||||
self.wrapper.errors_occurred = True
|
||||
six.reraise(dj_exc_type, dj_exc_value, traceback)
|
||||
raise dj_exc_value.with_traceback(traceback)
|
||||
|
||||
def __call__(self, func):
|
||||
# Note that we are intentionally not using @wraps here for performance
|
||||
|
||||
Reference in New Issue
Block a user