Commit 811d7870 authored by Markus Holtermann's avatar Markus Holtermann
Browse files

Moved migration exception classes to shared module

Thanks Aymeric Augustin for the review.
parent 3cb386b8
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
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
+2 −24
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ from django.utils.datastructures import OrderedSet
from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import total_ordering

from .exceptions import CircularDependencyError, NodeNotFoundError

RECURSION_DEPTH_WARNING = (
    "Maximum recursion depth exceeded while generating migration graph, "
    "falling back to iterative approach. If you're experiencing performance issues, "
@@ -276,27 +278,3 @@ class MigrationGraph(object):

    def __contains__(self, node):
        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
+3 −15
Original line number Diff line number Diff line
@@ -6,10 +6,12 @@ from importlib import import_module

from django.apps import apps
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.utils import six

from .exceptions import AmbiguityError, BadMigrationError, NodeNotFoundError

MIGRATIONS_MODULE_NAME = 'migrations'


@@ -324,17 +326,3 @@ class MigrationLoader(object):
        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))


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 −5
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@ from __future__ import unicode_literals
from django.db.transaction import atomic
from django.utils.encoding import python_2_unicode_compatible

from .exceptions import IrreversibleError


@python_2_unicode_compatible
class Migration(object):
@@ -39,10 +41,6 @@ class Migration(object):
    # are not applied.
    replaces = []

    # Error class which is raised when a migration is irreversible
    class IrreversibleError(RuntimeError):
        pass

    def __init__(self, name, app_label):
        self.name = name
        self.app_label = app_label
@@ -138,7 +136,7 @@ class Migration(object):
        for operation in self.operations:
            # If it's irreversible, error out
            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
            # over all operations
            new_state = new_state.clone()
+1 −3
Original line number Diff line number Diff line
@@ -18,9 +18,7 @@ from django.utils.functional import cached_property
from django.utils.module_loading import import_string
from django.utils.version import get_docs_version


class InvalidBasesError(ValueError):
    pass
from .exceptions import InvalidBasesError


def _get_app_label_and_model_name(model, app_label=''):
Loading