Commit d73c7e5d authored by Berker Peksag's avatar Berker Peksag Committed by Tim Graham
Browse files

[1.7.x] Limited lines to 119 characters in django/{contrib,db}.

Refs #23395.

Backport of c9178ef1 (to decrease chance of backport conflicts) from master
parent 9766ed6a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -162,7 +162,8 @@ class MigrationAutodetector(object):
            old_model_state = self.from_state.models[app_label, old_model_name]
            for field_name, field in old_model_state.fields:
                old_field = self.old_apps.get_model(app_label, old_model_name)._meta.get_field_by_name(field_name)[0]
                if hasattr(old_field, "rel") and getattr(old_field.rel, "through", None) and not old_field.rel.through._meta.auto_created:
                if (hasattr(old_field, "rel") and getattr(old_field.rel, "through", None)
                        and not old_field.rel.through._meta.auto_created):
                    through_key = (
                        old_field.rel.through._meta.app_label,
                        old_field.rel.through._meta.object_name.lower(),
@@ -961,7 +962,8 @@ class MigrationAutodetector(object):
            old_model_name = self.renamed_models.get((app_label, model_name), model_name)
            old_model_state = self.from_state.models[app_label, old_model_name]
            new_model_state = self.to_state.models[app_label, model_name]
            if old_model_state.options.get("order_with_respect_to", None) != new_model_state.options.get("order_with_respect_to", None):
            if (old_model_state.options.get("order_with_respect_to", None) !=
                    new_model_state.options.get("order_with_respect_to", None)):
                # Make sure it comes second if we're adding
                # (removal dependency is part of RemoveField)
                dependencies = []
+14 −5
Original line number Diff line number Diff line
@@ -37,9 +37,13 @@ class MigrationGraph(object):

    def add_dependency(self, migration, child, parent):
        if child not in self.nodes:
            raise KeyError("Migration %s dependencies reference nonexistent child node %r" % (migration, child))
            raise KeyError(
                "Migration %s dependencies reference nonexistent child node %r" % (migration, child)
            )
        if parent not in self.nodes:
            raise KeyError("Migration %s dependencies reference nonexistent parent node %r" % (migration, parent))
            raise KeyError(
                "Migration %s dependencies reference nonexistent parent node %r" % (migration, parent)
            )
        self.dependencies.setdefault(child, set()).add(parent)
        self.dependents.setdefault(parent, set()).add(child)

@@ -72,7 +76,8 @@ class MigrationGraph(object):
        """
        roots = set()
        for node in self.nodes:
            if not any(key[0] == node[0] for key in self.dependencies.get(node, set())) and (not app or app == node[0]):
            if (not any(key[0] == node[0] for key in self.dependencies.get(node, set()))
                    and (not app or app == node[0])):
                roots.add(node)
        return sorted(roots)

@@ -86,7 +91,8 @@ class MigrationGraph(object):
        """
        leaves = set()
        for node in self.nodes:
            if not any(key[0] == node[0] for key in self.dependents.get(node, set())) and (not app or app == node[0]):
            if (not any(key[0] == node[0] for key in self.dependents.get(node, set()))
                    and (not app or app == node[0])):
                leaves.add(node)
        return sorted(leaves)

@@ -116,7 +122,10 @@ class MigrationGraph(object):
        return list(OrderedSet(visited))

    def __str__(self):
        return "Graph: %s nodes, %s edges" % (len(self.nodes), sum(len(x) for x in self.dependencies.values()))
        return "Graph: %s nodes, %s edges" % (
            len(self.nodes),
            sum(len(x) for x in self.dependencies.values()),
        )

    def make_state(self, nodes=None, at_end=True, real_apps=None):
        """
+6 −2
Original line number Diff line number Diff line
@@ -108,7 +108,9 @@ class MigrationLoader(object):
                        break
                    raise
                if not hasattr(migration_module, "Migration"):
                    raise BadMigrationError("Migration %s in app %s has no Migration class" % (migration_name, app_config.label))
                    raise BadMigrationError(
                        "Migration %s in app %s has no Migration class" % (migration_name, app_config.label)
                    )
                # Ignore South-style migrations
                if hasattr(migration_module.Migration, "forwards"):
                    south_style_migrations = True
@@ -129,7 +131,9 @@ class MigrationLoader(object):
            if l == app_label and n.startswith(name_prefix):
                results.append((l, n))
        if len(results) > 1:
            raise AmbiguityError("There is more than one migration for '%s' with the prefix '%s'" % (app_label, name_prefix))
            raise AmbiguityError(
                "There is more than one migration for '%s' with the prefix '%s'" % (app_label, name_prefix)
            )
        elif len(results) == 0:
            raise KeyError("There no migrations for '%s' with the prefix '%s'" % (app_label, name_prefix))
        else:
+4 −2
Original line number Diff line number Diff line
@@ -90,7 +90,8 @@ class Migration(object):
            # there instead
            if collect_sql and not operation.reduces_to_sql:
                schema_editor.collected_sql.append("--")
                schema_editor.collected_sql.append("-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:")
                schema_editor.collected_sql.append("-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE "
                                                   "WRITTEN AS SQL:")
                schema_editor.collected_sql.append("-- %s" % operation.describe())
                schema_editor.collected_sql.append("--")
                continue
@@ -122,7 +123,8 @@ class Migration(object):
            # there instead
            if collect_sql and not operation.reduces_to_sql:
                schema_editor.collected_sql.append("--")
                schema_editor.collected_sql.append("-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:")
                schema_editor.collected_sql.append("-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE "
                                                   "WRITTEN AS SQL:")
                schema_editor.collected_sql.append("-- %s" % operation.describe())
                schema_editor.collected_sql.append("--")
                continue
+2 −1
Original line number Diff line number Diff line
@@ -174,7 +174,8 @@ class RenameField(Operation):
    def state_forwards(self, app_label, state):
        # Rename the field
        state.models[app_label, self.model_name.lower()].fields = [
            (self.new_name if n == self.old_name else n, f) for n, f in state.models[app_label, self.model_name.lower()].fields
            (self.new_name if n == self.old_name else n, f)
            for n, f in state.models[app_label, self.model_name.lower()].fields
        ]
        # Fix unique_together to refer to the new field
        options = state.models[app_label, self.model_name.lower()].options
Loading