[1.7.x] Limited lines to 119 characters in django/{contrib,db}.
Refs #23395.
Backport of c9178ef17a
(to decrease chance of backport conflicts) from master
This commit is contained in:
parent
9766ed6a0e
commit
d73c7e5db6
|
@ -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 = []
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -300,7 +300,8 @@ class MigrationOptimizer(object):
|
|||
return [other]
|
||||
|
||||
def reduce_add_field_rename_field(self, operation, other, in_between):
|
||||
if operation.model_name.lower() == other.model_name.lower() and operation.name.lower() == other.old_name.lower():
|
||||
if (operation.model_name.lower() == other.model_name.lower() and
|
||||
operation.name.lower() == other.old_name.lower()):
|
||||
return [
|
||||
migrations.AddField(
|
||||
model_name=operation.model_name,
|
||||
|
@ -310,7 +311,8 @@ class MigrationOptimizer(object):
|
|||
]
|
||||
|
||||
def reduce_alter_field_rename_field(self, operation, other, in_between):
|
||||
if operation.model_name.lower() == other.model_name.lower() and operation.name.lower() == other.old_name.lower():
|
||||
if (operation.model_name.lower() == other.model_name.lower() and
|
||||
operation.name.lower() == other.old_name.lower()):
|
||||
return [
|
||||
other,
|
||||
migrations.AlterField(
|
||||
|
@ -321,7 +323,8 @@ class MigrationOptimizer(object):
|
|||
]
|
||||
|
||||
def reduce_rename_field_self(self, operation, other, in_between):
|
||||
if operation.model_name.lower() == other.model_name.lower() and operation.new_name.lower() == other.old_name.lower():
|
||||
if (operation.model_name.lower() == other.model_name.lower() and
|
||||
operation.new_name.lower() == other.old_name.lower()):
|
||||
return [
|
||||
migrations.RenameField(
|
||||
operation.model_name,
|
||||
|
|
|
@ -163,11 +163,15 @@ class InteractiveMigrationQuestioner(MigrationQuestioner):
|
|||
|
||||
def ask_rename(self, model_name, old_name, new_name, field_instance):
|
||||
"Was this field really renamed?"
|
||||
return self._boolean_input("Did you rename %s.%s to %s.%s (a %s)? [y/N]" % (model_name, old_name, model_name, new_name, field_instance.__class__.__name__), False)
|
||||
msg = "Did you rename %s.%s to %s.%s (a %s)? [y/N]"
|
||||
return self._boolean_input(msg % (model_name, old_name, model_name, new_name,
|
||||
field_instance.__class__.__name__), False)
|
||||
|
||||
def ask_rename_model(self, old_model_state, new_model_state):
|
||||
"Was this model really renamed?"
|
||||
return self._boolean_input("Did you rename the %s.%s model to %s? [y/N]" % (old_model_state.app_label, old_model_state.name, new_model_state.name), False)
|
||||
msg = "Did you rename the %s.%s model to %s? [y/N]"
|
||||
return self._boolean_input(msg % (old_model_state.app_label, old_model_state.name,
|
||||
new_model_state.name), False)
|
||||
|
||||
def ask_merge(self, app_label):
|
||||
return self._boolean_input(
|
||||
|
|
|
@ -68,7 +68,12 @@ class ProjectState(object):
|
|||
except InvalidBasesError:
|
||||
new_unrendered_models.append(model)
|
||||
if len(new_unrendered_models) == len(unrendered_models):
|
||||
raise InvalidBasesError("Cannot resolve bases for %r\nThis can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)\n in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more" % new_unrendered_models)
|
||||
raise InvalidBasesError(
|
||||
"Cannot resolve bases for %r\nThis can happen if you are inheriting models from an "
|
||||
"app with migrations (e.g. contrib.auth)\n in an app with no migrations; see "
|
||||
"https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies "
|
||||
"for more" % new_unrendered_models
|
||||
)
|
||||
unrendered_models = new_unrendered_models
|
||||
# make sure apps has no dangling references
|
||||
if self.apps._pending_lookups:
|
||||
|
@ -78,16 +83,15 @@ class ProjectState(object):
|
|||
try:
|
||||
model = self.apps.get_model(lookup_model[0], lookup_model[1])
|
||||
except LookupError:
|
||||
if "%s.%s" % (lookup_model[0], lookup_model[1]) == settings.AUTH_USER_MODEL and ignore_swappable:
|
||||
app_label = "%s.%s" % (lookup_model[0], lookup_model[1])
|
||||
if app_label == settings.AUTH_USER_MODEL and ignore_swappable:
|
||||
continue
|
||||
# Raise an error with a best-effort helpful message
|
||||
# (only for the first issue). Error message should look like:
|
||||
# "ValueError: Lookup failed for model referenced by
|
||||
# field migrations.Book.author: migrations.Author"
|
||||
raise ValueError("Lookup failed for model referenced by field {field}: {model[0]}.{model[1]}".format(
|
||||
field=operations[0][1],
|
||||
model=lookup_model,
|
||||
))
|
||||
msg = "Lookup failed for model referenced by field {field}: {model[0]}.{model[1]}"
|
||||
raise ValueError(msg.format(field=operations[0][1], model=lookup_model))
|
||||
else:
|
||||
do_pending_lookups(model)
|
||||
try:
|
||||
|
@ -326,7 +330,8 @@ class ModelState(object):
|
|||
(self.app_label == other.app_label) and
|
||||
(self.name == other.name) and
|
||||
(len(self.fields) == len(other.fields)) and
|
||||
all((k1 == k2 and (f1.deconstruct()[1:] == f2.deconstruct()[1:])) for (k1, f1), (k2, f2) in zip(self.fields, other.fields)) and
|
||||
all((k1 == k2 and (f1.deconstruct()[1:] == f2.deconstruct()[1:]))
|
||||
for (k1, f1), (k2, f2) in zip(self.fields, other.fields)) and
|
||||
(self.options == other.options) and
|
||||
(self.bases == other.bases)
|
||||
)
|
||||
|
|
|
@ -155,10 +155,12 @@ class MigrationWriter(object):
|
|||
imports.discard("from django.db import models")
|
||||
items["imports"] = "\n".join(imports) + "\n" if imports else ""
|
||||
if migration_imports:
|
||||
items["imports"] += "\n\n# Functions from the following migrations need manual copying.\n# Move them and any dependencies into this file, then update the\n# RunPython operations to refer to the local versions:\n# %s" % (
|
||||
"\n# ".join(migration_imports)
|
||||
)
|
||||
|
||||
items["imports"] += (
|
||||
"\n\n# Functions from the following migrations need manual "
|
||||
"copying.\n# Move them and any dependencies into this file, "
|
||||
"then update the\n# RunPython operations to refer to the local "
|
||||
"versions:\n# %s"
|
||||
) % "\n# ".join(migration_imports)
|
||||
# If there's a replaces, make a string for it
|
||||
if self.migration.replaces:
|
||||
items['replaces_str'] = "\n replaces = %s\n" % self.serialize(self.migration.replaces)[0]
|
||||
|
@ -394,7 +396,11 @@ class MigrationWriter(object):
|
|||
return "re.compile(%s)" % ', '.join(args), imports
|
||||
# Uh oh.
|
||||
else:
|
||||
raise ValueError("Cannot serialize: %r\nThere are some values Django cannot serialize into migration files.\nFor more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing" % value)
|
||||
raise ValueError(
|
||||
"Cannot serialize: %r\nThere are some values Django cannot serialize into "
|
||||
"migration files.\nFor more, see https://docs.djangoproject.com/en/dev/"
|
||||
"topics/migrations/#migration-serializing" % value
|
||||
)
|
||||
|
||||
|
||||
MIGRATION_TEMPLATE = """\
|
||||
|
|
Loading…
Reference in New Issue