mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Made Operation.references_model/references_field require app_label.
This will allow them to drop a ton of logic to deal with null app_label.
This commit is contained in:
committed by
Mariusz Felisiak
parent
25bf15c0da
commit
8069526ce3
@@ -80,10 +80,10 @@ class Operation:
|
||||
"""
|
||||
return "%s: %s" % (self.__class__.__name__, self._constructor_args)
|
||||
|
||||
def references_model(self, name, app_label=None):
|
||||
def references_model(self, name, app_label):
|
||||
"""
|
||||
Return True if there is a chance this operation references the given
|
||||
model name (as a string), with an optional app label for accuracy.
|
||||
model name (as a string), with an app label for accuracy.
|
||||
|
||||
Used for optimization. If in doubt, return True;
|
||||
returning a false positive will merely make the optimizer a little
|
||||
@@ -92,10 +92,10 @@ class Operation:
|
||||
"""
|
||||
return True
|
||||
|
||||
def references_field(self, model_name, name, app_label=None):
|
||||
def references_field(self, model_name, name, app_label):
|
||||
"""
|
||||
Return True if there is a chance this operation references the given
|
||||
field name, with an optional app label for accuracy.
|
||||
field name, with an app label for accuracy.
|
||||
|
||||
Used for optimization. If in doubt, return True.
|
||||
"""
|
||||
|
||||
@@ -28,7 +28,7 @@ class FieldOperation(Operation):
|
||||
def is_same_field_operation(self, operation):
|
||||
return self.is_same_model_operation(operation) and self.name_lower == operation.name_lower
|
||||
|
||||
def references_model(self, name, app_label=None):
|
||||
def references_model(self, name, app_label):
|
||||
name_lower = name.lower()
|
||||
if name_lower == self.model_name_lower:
|
||||
return True
|
||||
@@ -36,7 +36,7 @@ class FieldOperation(Operation):
|
||||
return field_references_model(self.field, ModelTuple(app_label, name_lower))
|
||||
return False
|
||||
|
||||
def references_field(self, model_name, name, app_label=None):
|
||||
def references_field(self, model_name, name, app_label):
|
||||
model_name_lower = model_name.lower()
|
||||
# Check if this operation locally references the field.
|
||||
if model_name_lower == self.model_name_lower:
|
||||
@@ -376,8 +376,8 @@ class RenameField(FieldOperation):
|
||||
def describe(self):
|
||||
return "Rename field %s on %s to %s" % (self.old_name, self.model_name, self.new_name)
|
||||
|
||||
def references_field(self, model_name, name, app_label=None):
|
||||
return self.references_model(model_name) and (
|
||||
def references_field(self, model_name, name, app_label):
|
||||
return self.references_model(model_name, app_label) and (
|
||||
name.lower() == self.old_name_lower or
|
||||
name.lower() == self.new_name_lower
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ class ModelOperation(Operation):
|
||||
def name_lower(self):
|
||||
return self.name.lower()
|
||||
|
||||
def references_model(self, name, app_label=None):
|
||||
def references_model(self, name, app_label):
|
||||
return name.lower() == self.name_lower
|
||||
|
||||
def reduce(self, operation, app_label):
|
||||
@@ -99,7 +99,7 @@ class CreateModel(ModelOperation):
|
||||
def describe(self):
|
||||
return "Create %smodel %s" % ("proxy " if self.options.get("proxy", False) else "", self.name)
|
||||
|
||||
def references_model(self, name, app_label=None):
|
||||
def references_model(self, name, app_label):
|
||||
name_lower = name.lower()
|
||||
if name_lower == self.name_lower:
|
||||
return True
|
||||
@@ -265,7 +265,7 @@ class DeleteModel(ModelOperation):
|
||||
if self.allow_migrate_model(schema_editor.connection.alias, model):
|
||||
schema_editor.create_model(model)
|
||||
|
||||
def references_model(self, name, app_label=None):
|
||||
def references_model(self, name, app_label):
|
||||
# The deleted model could be referencing the specified model through
|
||||
# related fields.
|
||||
return True
|
||||
@@ -402,7 +402,7 @@ class RenameModel(ModelOperation):
|
||||
self.new_name_lower, self.old_name_lower = self.old_name_lower, self.new_name_lower
|
||||
self.new_name, self.old_name = self.old_name, self.new_name
|
||||
|
||||
def references_model(self, name, app_label=None):
|
||||
def references_model(self, name, app_label):
|
||||
return (
|
||||
name.lower() == self.old_name_lower or
|
||||
name.lower() == self.new_name_lower
|
||||
@@ -528,7 +528,7 @@ class AlterTogetherOptionOperation(ModelOptionOperation):
|
||||
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||
return self.database_forwards(app_label, schema_editor, from_state, to_state)
|
||||
|
||||
def references_field(self, model_name, name, app_label=None):
|
||||
def references_field(self, model_name, name, app_label):
|
||||
return (
|
||||
self.references_model(model_name, app_label) and
|
||||
(
|
||||
@@ -609,7 +609,7 @@ class AlterOrderWithRespectTo(ModelOptionOperation):
|
||||
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||
self.database_forwards(app_label, schema_editor, from_state, to_state)
|
||||
|
||||
def references_field(self, model_name, name, app_label=None):
|
||||
def references_field(self, model_name, name, app_label):
|
||||
return (
|
||||
self.references_model(model_name, app_label) and
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user