From 6e50fc924610119fd659bc0821c9c059c7d03c62 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 9 Feb 2015 08:53:58 -0500 Subject: [PATCH] [1.8.x] Removed unnecessary parentheses in model check messages. Backport of e144e0e237136f8bf1831f645c3dde4541d629b0 from master --- django/db/models/base.py | 36 ++++++++------ tests/invalid_models_tests/test_models.py | 59 ++++++++++++----------- 2 files changed, 50 insertions(+), 45 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index f95c182566..9f93d86f98 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1200,7 +1200,8 @@ class Model(six.with_metaclass(ModelBase)): app_label, model_name = cls._meta.swapped.split('.') errors.append( checks.Error( - ("'%s' references '%s.%s', which has not been installed, or is abstract.") % ( + "'%s' references '%s.%s', which has not been " + "installed, or is abstract." % ( cls._meta.swappable, app_label, model_name ), hint=None, @@ -1266,8 +1267,8 @@ class Model(six.with_metaclass(ModelBase)): if signature in seen_intermediary_signatures: errors.append( checks.Error( - ("The model has two many-to-many relations through " - "the intermediate model '%s.%s'.") % ( + "The model has two many-to-many relations through " + "the intermediate model '%s.%s'." % ( f.rel.through._meta.app_label, f.rel.through._meta.object_name ), @@ -1290,8 +1291,8 @@ class Model(six.with_metaclass(ModelBase)): if fields and not fields[0].primary_key and cls._meta.pk.name == 'id': return [ checks.Error( - ("'id' can only be used as a field name if the field also " - "sets 'primary_key=True'."), + "'id' can only be used as a field name if the field also " + "sets 'primary_key=True'.", hint=None, obj=cls, id='models.E004', @@ -1314,9 +1315,9 @@ class Model(six.with_metaclass(ModelBase)): if clash: errors.append( checks.Error( - ("The field '%s' from parent model " - "'%s' clashes with the field '%s' " - "from parent model '%s'.") % ( + "The field '%s' from parent model " + "'%s' clashes with the field '%s' " + "from parent model '%s'." % ( clash.name, clash.model._meta, f.name, f.model._meta ), @@ -1341,8 +1342,8 @@ class Model(six.with_metaclass(ModelBase)): if clash and not id_conflict: errors.append( checks.Error( - ("The field '%s' clashes with the field '%s' " - "from model '%s'.") % ( + "The field '%s' clashes with the field '%s' " + "from model '%s'." % ( f.name, clash.name, clash.model._meta ), hint=None, @@ -1368,7 +1369,8 @@ class Model(six.with_metaclass(ModelBase)): if column_name and column_name in used_column_names: errors.append( checks.Error( - "Field '%s' has column name '%s' that is used by another field." % (f.name, column_name), + "Field '%s' has column name '%s' that is used by " + "another field." % (f.name, column_name), hint="Specify a 'db_column' for the field.", obj=cls, id='models.E007' @@ -1456,7 +1458,9 @@ class Model(six.with_metaclass(ModelBase)): except KeyError: errors.append( checks.Error( - "'%s' refers to the non-existent field '%s'." % (option, field_name), + "'%s' refers to the non-existent field '%s'." % ( + option, field_name, + ), hint=None, obj=cls, id='models.E012', @@ -1466,9 +1470,9 @@ class Model(six.with_metaclass(ModelBase)): if isinstance(field.rel, models.ManyToManyRel): errors.append( checks.Error( - ("'%s' refers to a ManyToManyField '%s', but " - "ManyToManyFields are not permitted in '%s'.") % ( - option, field_name, option + "'%s' refers to a ManyToManyField '%s', but " + "ManyToManyFields are not permitted in '%s'." % ( + option, field_name, option, ), hint=None, obj=cls, @@ -1480,7 +1484,7 @@ class Model(six.with_metaclass(ModelBase)): checks.Error( ("'%s' refers to field '%s' which is not local " "to model '%s'.") % ( - option, field_name, cls._meta.object_name + option, field_name, cls._meta.object_name, ), hint=("This issue may be caused by multi-table " "inheritance."), diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index f67223963b..35bde5a8ed 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -114,8 +114,8 @@ class IndexTogetherTests(IsolatedModelsTestCase): errors = Bar.check() expected = [ Error( - ("'index_together' refers to field 'field1' which is not " - "local to model 'Bar'."), + "'index_together' refers to field 'field1' which is not " + "local to model 'Bar'.", hint=("This issue may be caused by multi-table inheritance."), obj=Bar, id='models.E016', @@ -135,8 +135,8 @@ class IndexTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ("'index_together' refers to a ManyToManyField 'm2m', but " - "ManyToManyFields are not permitted in 'index_together'."), + "'index_together' refers to a ManyToManyField 'm2m', but " + "ManyToManyFields are not permitted in 'index_together'.", hint=None, obj=Model, id='models.E013', @@ -241,8 +241,8 @@ class UniqueTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ("'unique_together' refers to a ManyToManyField 'm2m', but " - "ManyToManyFields are not permitted in 'unique_together'."), + "'unique_together' refers to a ManyToManyField 'm2m', but " + "ManyToManyFields are not permitted in 'unique_together'.", hint=None, obj=Model, id='models.E013', @@ -330,9 +330,9 @@ class FieldNamesTests(IsolatedModelsTestCase): m2m_long_name = "verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_id" expected = [ Error( - ('Autogenerated column name too long for M2M field "%s". ' + 'Autogenerated column name too long for M2M field "%s". ' 'Maximum length is "%s" for database "%s".' - % (m2m_long_name, self.max_column_name_length, self.column_limit_db_alias)), + % (m2m_long_name, self.max_column_name_length, self.column_limit_db_alias), hint=("Use 'through' to create a separate model for " "M2M and then set column_name using 'db_column'."), obj=ModelWithLongField, @@ -347,9 +347,9 @@ class FieldNamesTests(IsolatedModelsTestCase): # name is longer than the limits of the database. expected.append( Error( - ('Autogenerated column name too long for M2M field "%s_id". ' + 'Autogenerated column name too long for M2M field "%s_id". ' 'Maximum length is "%s" for database "%s".' - % (long_field_name, self.max_column_name_length, self.column_limit_db_alias)), + % (long_field_name, self.max_column_name_length, self.column_limit_db_alias), hint=("Use 'through' to create a separate model for " "M2M and then set column_name using 'db_column'."), obj=ModelWithLongField, @@ -382,9 +382,9 @@ class FieldNamesTests(IsolatedModelsTestCase): # without specifying db_column expected = [ Error( - ('Autogenerated column name too long for field "%s". ' + 'Autogenerated column name too long for field "%s". ' 'Maximum length is "%s" for database "%s".' - % (long_field_name, self.max_column_name_length, self.column_limit_db_alias)), + % (long_field_name, self.max_column_name_length, self.column_limit_db_alias), hint="Set the column name manually using 'db_column'.", obj=ModelWithLongField, id='models.E018', @@ -441,17 +441,17 @@ class ShadowingFieldsTests(IsolatedModelsTestCase): errors = Child.check() expected = [ Error( - ("The field 'id' from parent model " - "'invalid_models_tests.mother' clashes with the field 'id' " - "from parent model 'invalid_models_tests.father'."), + "The field 'id' from parent model " + "'invalid_models_tests.mother' clashes with the field 'id' " + "from parent model 'invalid_models_tests.father'.", hint=None, obj=Child, id='models.E005', ), Error( - ("The field 'clash' from parent model " - "'invalid_models_tests.mother' clashes with the field 'clash' " - "from parent model 'invalid_models_tests.father'."), + "The field 'clash' from parent model " + "'invalid_models_tests.mother' clashes with the field 'clash' " + "from parent model 'invalid_models_tests.father'.", hint=None, obj=Child, id='models.E005', @@ -474,8 +474,8 @@ class ShadowingFieldsTests(IsolatedModelsTestCase): errors = Child.check() expected = [ Error( - ("The field 'f' clashes with the field 'f_id' " - "from model 'invalid_models_tests.parent'."), + "The field 'f' clashes with the field 'f_id' " + "from model 'invalid_models_tests.parent'.", hint=None, obj=Child._meta.get_field('f'), id='models.E006', @@ -519,8 +519,8 @@ class ShadowingFieldsTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ("The field 'fk_id' clashes with the field 'fk' from model " - "'invalid_models_tests.model'."), + "The field 'fk_id' clashes with the field 'fk' from model " + "'invalid_models_tests.model'.", hint=None, obj=Model._meta.get_field('fk_id'), id='models.E006', @@ -540,7 +540,8 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - "'id' can only be used as a field name if the field also sets 'primary_key=True'.", + "'id' can only be used as a field name if the field also sets " + "'primary_key=True'.", hint=None, obj=Model, id='models.E004', @@ -556,8 +557,8 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ("'ordering' must be a tuple or list " - "(even if you want to order by only one field)."), + "'ordering' must be a tuple or list " + "(even if you want to order by only one field).", hint=None, obj=Model, id='models.E014', @@ -662,8 +663,8 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ("'TEST_SWAPPED_MODEL_BAD_MODEL' references 'not_an_app.Target', " - 'which has not been installed, or is abstract.'), + "'TEST_SWAPPED_MODEL_BAD_MODEL' references 'not_an_app.Target', " + 'which has not been installed, or is abstract.', hint=None, obj=None, id='models.E002', @@ -688,8 +689,8 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Group.check() expected = [ Error( - ("The model has two many-to-many relations through " - "the intermediate model 'invalid_models_tests.Membership'."), + "The model has two many-to-many relations through " + "the intermediate model 'invalid_models_tests.Membership'.", hint=None, obj=Group, id='models.E003',