Moved migration exception classes to shared module
Thanks Aymeric Augustin for the review.
This commit is contained in:
parent
3cb386b8c2
commit
811d7870a5
|
@ -0,0 +1,55 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
|
|
||||||
|
class AmbiguityError(Exception):
|
||||||
|
"""
|
||||||
|
Raised when more than one migration matches a name prefix.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class BadMigrationError(Exception):
|
||||||
|
"""
|
||||||
|
Raised when there's a bad migration (unreadable/bad format/etc.).
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class CircularDependencyError(Exception):
|
||||||
|
"""
|
||||||
|
Raised when there's an impossible-to-resolve circular dependency.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidBasesError(ValueError):
|
||||||
|
"""
|
||||||
|
Raised when a model's base classes can't be resolved.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class IrreversibleError(RuntimeError):
|
||||||
|
"""
|
||||||
|
Raised when a irreversible migration is about to be reversed.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
|
class NodeNotFoundError(LookupError):
|
||||||
|
"""
|
||||||
|
Raised when an attempt on a node is made that is not available in the graph.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, message, node):
|
||||||
|
self.message = message
|
||||||
|
self.node = node
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.message
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "NodeNotFoundError(%r)" % self.node
|
|
@ -8,6 +8,8 @@ from django.utils.datastructures import OrderedSet
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.functional import total_ordering
|
from django.utils.functional import total_ordering
|
||||||
|
|
||||||
|
from .exceptions import CircularDependencyError, NodeNotFoundError
|
||||||
|
|
||||||
RECURSION_DEPTH_WARNING = (
|
RECURSION_DEPTH_WARNING = (
|
||||||
"Maximum recursion depth exceeded while generating migration graph, "
|
"Maximum recursion depth exceeded while generating migration graph, "
|
||||||
"falling back to iterative approach. If you're experiencing performance issues, "
|
"falling back to iterative approach. If you're experiencing performance issues, "
|
||||||
|
@ -276,27 +278,3 @@ class MigrationGraph(object):
|
||||||
|
|
||||||
def __contains__(self, node):
|
def __contains__(self, node):
|
||||||
return node in self.nodes
|
return node in self.nodes
|
||||||
|
|
||||||
|
|
||||||
class CircularDependencyError(Exception):
|
|
||||||
"""
|
|
||||||
Raised when there's an impossible-to-resolve circular dependency.
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class NodeNotFoundError(LookupError):
|
|
||||||
"""
|
|
||||||
Raised when an attempt on a node is made that is not available in the graph.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, message, node):
|
|
||||||
self.message = message
|
|
||||||
self.node = node
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.message
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "NodeNotFoundError(%r)" % self.node
|
|
||||||
|
|
|
@ -6,10 +6,12 @@ from importlib import import_module
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.migrations.graph import MigrationGraph, NodeNotFoundError
|
from django.db.migrations.graph import MigrationGraph
|
||||||
from django.db.migrations.recorder import MigrationRecorder
|
from django.db.migrations.recorder import MigrationRecorder
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
|
from .exceptions import AmbiguityError, BadMigrationError, NodeNotFoundError
|
||||||
|
|
||||||
MIGRATIONS_MODULE_NAME = 'migrations'
|
MIGRATIONS_MODULE_NAME = 'migrations'
|
||||||
|
|
||||||
|
|
||||||
|
@ -324,17 +326,3 @@ class MigrationLoader(object):
|
||||||
See graph.make_state for the meaning of "nodes" and "at_end"
|
See graph.make_state for the meaning of "nodes" and "at_end"
|
||||||
"""
|
"""
|
||||||
return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
|
return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
|
||||||
|
|
||||||
|
|
||||||
class BadMigrationError(Exception):
|
|
||||||
"""
|
|
||||||
Raised when there's a bad migration (unreadable/bad format/etc.)
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class AmbiguityError(Exception):
|
|
||||||
"""
|
|
||||||
Raised when more than one migration matches a name prefix
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ from __future__ import unicode_literals
|
||||||
from django.db.transaction import atomic
|
from django.db.transaction import atomic
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
|
from .exceptions import IrreversibleError
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Migration(object):
|
class Migration(object):
|
||||||
|
@ -39,10 +41,6 @@ class Migration(object):
|
||||||
# are not applied.
|
# are not applied.
|
||||||
replaces = []
|
replaces = []
|
||||||
|
|
||||||
# Error class which is raised when a migration is irreversible
|
|
||||||
class IrreversibleError(RuntimeError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __init__(self, name, app_label):
|
def __init__(self, name, app_label):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.app_label = app_label
|
self.app_label = app_label
|
||||||
|
@ -138,7 +136,7 @@ class Migration(object):
|
||||||
for operation in self.operations:
|
for operation in self.operations:
|
||||||
# If it's irreversible, error out
|
# If it's irreversible, error out
|
||||||
if not operation.reversible:
|
if not operation.reversible:
|
||||||
raise Migration.IrreversibleError("Operation %s in %s is not reversible" % (operation, self))
|
raise IrreversibleError("Operation %s in %s is not reversible" % (operation, self))
|
||||||
# Preserve new state from previous run to not tamper the same state
|
# Preserve new state from previous run to not tamper the same state
|
||||||
# over all operations
|
# over all operations
|
||||||
new_state = new_state.clone()
|
new_state = new_state.clone()
|
||||||
|
|
|
@ -18,9 +18,7 @@ from django.utils.functional import cached_property
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
from django.utils.version import get_docs_version
|
from django.utils.version import get_docs_version
|
||||||
|
|
||||||
|
from .exceptions import InvalidBasesError
|
||||||
class InvalidBasesError(ValueError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _get_app_label_and_model_name(model, app_label=''):
|
def _get_app_label_and_model_name(model, app_label=''):
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from django.db.migrations.graph import (
|
from django.db.migrations.exceptions import (
|
||||||
RECURSION_DEPTH_WARNING, CircularDependencyError, MigrationGraph,
|
CircularDependencyError, NodeNotFoundError,
|
||||||
NodeNotFoundError,
|
|
||||||
)
|
)
|
||||||
|
from django.db.migrations.graph import RECURSION_DEPTH_WARNING, MigrationGraph
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ from __future__ import unicode_literals
|
||||||
from unittest import skipIf
|
from unittest import skipIf
|
||||||
|
|
||||||
from django.db import connection, connections
|
from django.db import connection, connections
|
||||||
from django.db.migrations.graph import NodeNotFoundError
|
from django.db.migrations.exceptions import AmbiguityError, NodeNotFoundError
|
||||||
from django.db.migrations.loader import AmbiguityError, MigrationLoader
|
from django.db.migrations.loader import MigrationLoader
|
||||||
from django.db.migrations.recorder import MigrationRecorder
|
from django.db.migrations.recorder import MigrationRecorder
|
||||||
from django.test import TestCase, modify_settings, override_settings
|
from django.test import TestCase, modify_settings, override_settings
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
from django.apps.registry import Apps
|
from django.apps.registry import Apps
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.migrations.exceptions import InvalidBasesError
|
||||||
from django.db.migrations.operations import (
|
from django.db.migrations.operations import (
|
||||||
AddField, AlterField, DeleteModel, RemoveField,
|
AddField, AlterField, DeleteModel, RemoveField,
|
||||||
)
|
)
|
||||||
from django.db.migrations.state import (
|
from django.db.migrations.state import (
|
||||||
InvalidBasesError, ModelState, ProjectState, get_related_models_recursive,
|
ModelState, ProjectState, get_related_models_recursive,
|
||||||
)
|
)
|
||||||
from django.test import SimpleTestCase, TestCase, override_settings
|
from django.test import SimpleTestCase, TestCase, override_settings
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
Loading…
Reference in New Issue