2014-01-20 10:45:21 +08:00
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-06-10 20:04:19 +08:00
|
|
|
import unittest
|
2016-04-23 00:59:41 +08:00
|
|
|
import warnings
|
2014-06-10 20:04:19 +08:00
|
|
|
|
|
|
|
from django.conf import settings
|
2014-01-20 10:45:21 +08:00
|
|
|
from django.core.checks import Error
|
2016-08-17 02:23:30 +08:00
|
|
|
from django.core.checks.model_checks import _check_lazy_references
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.db import connections, models
|
2016-08-17 02:23:30 +08:00
|
|
|
from django.db.models.signals import post_init
|
2015-11-17 13:39:28 +08:00
|
|
|
from django.test import SimpleTestCase
|
|
|
|
from django.test.utils import isolate_apps, override_settings
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
|
2014-06-10 20:04:19 +08:00
|
|
|
def get_max_column_name_length():
|
|
|
|
allowed_len = None
|
|
|
|
db_alias = None
|
|
|
|
|
|
|
|
for db in settings.DATABASES.keys():
|
|
|
|
connection = connections[db]
|
|
|
|
max_name_length = connection.ops.max_name_length()
|
2014-07-15 00:23:57 +08:00
|
|
|
if max_name_length is None or connection.features.truncates_names:
|
2014-06-10 20:04:19 +08:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if allowed_len is None:
|
|
|
|
allowed_len = max_name_length
|
|
|
|
db_alias = db
|
|
|
|
elif max_name_length < allowed_len:
|
|
|
|
allowed_len = max_name_length
|
|
|
|
db_alias = db
|
|
|
|
|
|
|
|
return (allowed_len, db_alias)
|
|
|
|
|
|
|
|
|
2015-11-17 13:39:28 +08:00
|
|
|
@isolate_apps('invalid_models_tests')
|
|
|
|
class IndexTogetherTests(SimpleTestCase):
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
def test_non_iterable(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
index_together = 42
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"'index_together' must be a list or tuple.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E008',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
def test_non_list(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
index_together = 'not-a-list'
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"'index_together' must be a list or tuple.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E008',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
def test_list_containing_non_iterable(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
2014-03-02 03:06:15 +08:00
|
|
|
index_together = [('a', 'b'), 42]
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"All 'index_together' elements must be lists or tuples.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E009',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
def test_pointing_to_missing_field(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
index_together = [
|
|
|
|
["missing_field"],
|
|
|
|
]
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"'index_together' refers to the non-existent field 'missing_field'.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E012',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-04-15 02:41:47 +08:00
|
|
|
def test_pointing_to_non_local_field(self):
|
|
|
|
class Foo(models.Model):
|
|
|
|
field1 = models.IntegerField()
|
|
|
|
|
|
|
|
class Bar(Foo):
|
|
|
|
field2 = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
index_together = [
|
|
|
|
["field2", "field1"],
|
|
|
|
]
|
|
|
|
|
|
|
|
errors = Bar.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"'index_together' refers to field 'field1' which is not "
|
|
|
|
"local to model 'Bar'.",
|
2014-04-15 02:41:47 +08:00
|
|
|
hint=("This issue may be caused by multi-table inheritance."),
|
|
|
|
obj=Bar,
|
|
|
|
id='models.E016',
|
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-01-20 10:45:21 +08:00
|
|
|
def test_pointing_to_m2m_field(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
m2m = models.ManyToManyField('self')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
index_together = [
|
|
|
|
["m2m"],
|
|
|
|
]
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"'index_together' refers to a ManyToManyField 'm2m', but "
|
|
|
|
"ManyToManyFields are not permitted in 'index_together'.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E013',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
|
|
|
|
# unique_together tests are very similar to index_together tests.
|
2015-11-17 13:39:28 +08:00
|
|
|
@isolate_apps('invalid_models_tests')
|
|
|
|
class UniqueTogetherTests(SimpleTestCase):
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
def test_non_iterable(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
unique_together = 42
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"'unique_together' must be a list or tuple.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E010',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
def test_list_containing_non_iterable(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
one = models.IntegerField()
|
|
|
|
two = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [('a', 'b'), 42]
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"All 'unique_together' elements must be lists or tuples.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E011',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-03-02 03:06:15 +08:00
|
|
|
def test_non_list(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
unique_together = 'not-a-list'
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"'unique_together' must be a list or tuple.",
|
2014-03-02 03:06:15 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E010',
|
2014-03-02 03:06:15 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-01-20 10:45:21 +08:00
|
|
|
def test_valid_model(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
one = models.IntegerField()
|
|
|
|
two = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
# unique_together can be a simple tuple
|
|
|
|
unique_together = ('one', 'two')
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
self.assertEqual(errors, [])
|
|
|
|
|
|
|
|
def test_pointing_to_missing_field(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
unique_together = [
|
|
|
|
["missing_field"],
|
|
|
|
]
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"'unique_together' refers to the non-existent field 'missing_field'.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E012',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
def test_pointing_to_m2m(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
m2m = models.ManyToManyField('self')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [
|
|
|
|
["m2m"],
|
|
|
|
]
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"'unique_together' refers to a ManyToManyField 'm2m', but "
|
|
|
|
"ManyToManyFields are not permitted in 'unique_together'.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E013',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
|
2015-11-17 13:39:28 +08:00
|
|
|
@isolate_apps('invalid_models_tests')
|
|
|
|
class FieldNamesTests(SimpleTestCase):
|
2014-01-20 10:45:21 +08:00
|
|
|
|
2014-02-08 05:34:56 +08:00
|
|
|
def test_ending_with_underscore(self):
|
2014-01-20 10:45:21 +08:00
|
|
|
class Model(models.Model):
|
2014-02-08 05:34:56 +08:00
|
|
|
field_ = models.CharField(max_length=10)
|
|
|
|
m2m_ = models.ManyToManyField('self')
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 18:18:39 +08:00
|
|
|
'Field names must not end with an underscore.',
|
2014-02-08 05:34:56 +08:00
|
|
|
obj=Model._meta.get_field('field_'),
|
2014-03-03 18:18:39 +08:00
|
|
|
id='fields.E001',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
Error(
|
2014-03-03 18:18:39 +08:00
|
|
|
'Field names must not end with an underscore.',
|
2014-02-08 05:34:56 +08:00
|
|
|
obj=Model._meta.get_field('m2m_'),
|
2014-03-03 18:18:39 +08:00
|
|
|
id='fields.E001',
|
2014-02-08 05:34:56 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-06-10 20:04:19 +08:00
|
|
|
max_column_name_length, column_limit_db_alias = get_max_column_name_length()
|
|
|
|
|
2016-04-08 10:04:45 +08:00
|
|
|
@unittest.skipIf(max_column_name_length is None, "The database doesn't have a column name length limit.")
|
2014-06-10 20:04:19 +08:00
|
|
|
def test_M2M_long_column_name(self):
|
|
|
|
"""
|
|
|
|
#13711 -- Model check for long M2M column names when database has
|
|
|
|
column name length limits.
|
|
|
|
"""
|
|
|
|
allowed_len, db_alias = get_max_column_name_length()
|
|
|
|
|
|
|
|
# A model with very long name which will be used to set relations to.
|
|
|
|
class VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz(models.Model):
|
|
|
|
title = models.CharField(max_length=11)
|
|
|
|
|
|
|
|
# Main model for which checks will be performed.
|
|
|
|
class ModelWithLongField(models.Model):
|
|
|
|
m2m_field = models.ManyToManyField(
|
|
|
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
|
|
|
related_name="rn1"
|
|
|
|
)
|
|
|
|
m2m_field2 = models.ManyToManyField(
|
|
|
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
|
|
|
related_name="rn2", through='m2msimple'
|
|
|
|
)
|
|
|
|
m2m_field3 = models.ManyToManyField(
|
|
|
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
|
|
|
related_name="rn3",
|
|
|
|
through='m2mcomplex'
|
|
|
|
)
|
2015-07-22 22:43:21 +08:00
|
|
|
fk = models.ForeignKey(
|
|
|
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
|
|
|
models.CASCADE,
|
|
|
|
related_name="rn4",
|
|
|
|
)
|
2014-06-10 20:04:19 +08:00
|
|
|
|
|
|
|
# Models used for setting `through` in M2M field.
|
|
|
|
class m2msimple(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
id2 = models.ForeignKey(ModelWithLongField, models.CASCADE)
|
2014-06-10 20:04:19 +08:00
|
|
|
|
|
|
|
class m2mcomplex(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
id2 = models.ForeignKey(ModelWithLongField, models.CASCADE)
|
2014-06-10 20:04:19 +08:00
|
|
|
|
|
|
|
long_field_name = 'a' * (self.max_column_name_length + 1)
|
|
|
|
models.ForeignKey(
|
2015-07-22 22:43:21 +08:00
|
|
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
|
|
|
models.CASCADE,
|
2014-06-10 20:04:19 +08:00
|
|
|
).contribute_to_class(m2msimple, long_field_name)
|
|
|
|
|
|
|
|
models.ForeignKey(
|
|
|
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
2015-07-22 22:43:21 +08:00
|
|
|
models.CASCADE,
|
2014-06-10 20:04:19 +08:00
|
|
|
db_column=long_field_name
|
|
|
|
).contribute_to_class(m2mcomplex, long_field_name)
|
|
|
|
|
|
|
|
errors = ModelWithLongField.check()
|
|
|
|
|
|
|
|
# First error because of M2M field set on the model with long name.
|
|
|
|
m2m_long_name = "verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_id"
|
2015-07-03 10:09:51 +08:00
|
|
|
if self.max_column_name_length > len(m2m_long_name):
|
|
|
|
# Some databases support names longer than the test name.
|
|
|
|
expected = []
|
|
|
|
else:
|
|
|
|
expected = [
|
|
|
|
Error(
|
|
|
|
'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),
|
2016-04-08 10:04:45 +08:00
|
|
|
hint="Use 'through' to create a separate model for "
|
|
|
|
"M2M and then set column_name using 'db_column'.",
|
2015-07-03 10:09:51 +08:00
|
|
|
obj=ModelWithLongField,
|
|
|
|
id='models.E019',
|
|
|
|
)
|
|
|
|
]
|
2014-06-10 20:04:19 +08:00
|
|
|
|
|
|
|
# Second error because the FK specified in the `through` model
|
2015-12-03 07:55:50 +08:00
|
|
|
# `m2msimple` has auto-generated name longer than allowed.
|
2014-06-10 20:04:19 +08:00
|
|
|
# There will be no check errors in the other M2M because it
|
|
|
|
# specifies db_column for the FK in `through` model even if the actual
|
|
|
|
# name is longer than the limits of the database.
|
|
|
|
expected.append(
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
'Autogenerated column name too long for M2M field "%s_id". '
|
2014-06-10 20:04:19 +08:00
|
|
|
'Maximum length is "%s" for database "%s".'
|
2015-02-09 21:53:58 +08:00
|
|
|
% (long_field_name, self.max_column_name_length, self.column_limit_db_alias),
|
2016-04-08 10:04:45 +08:00
|
|
|
hint="Use 'through' to create a separate model for "
|
|
|
|
"M2M and then set column_name using 'db_column'.",
|
2014-06-10 20:04:19 +08:00
|
|
|
obj=ModelWithLongField,
|
|
|
|
id='models.E019',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2016-04-08 10:04:45 +08:00
|
|
|
@unittest.skipIf(max_column_name_length is None, "The database doesn't have a column name length limit.")
|
2014-06-10 20:04:19 +08:00
|
|
|
def test_local_field_long_column_name(self):
|
|
|
|
"""
|
|
|
|
#13711 -- Model check for long column names
|
|
|
|
when database does not support long names.
|
|
|
|
"""
|
|
|
|
allowed_len, db_alias = get_max_column_name_length()
|
|
|
|
|
|
|
|
class ModelWithLongField(models.Model):
|
|
|
|
title = models.CharField(max_length=11)
|
|
|
|
|
|
|
|
long_field_name = 'a' * (self.max_column_name_length + 1)
|
|
|
|
long_field_name2 = 'b' * (self.max_column_name_length + 1)
|
|
|
|
models.CharField(max_length=11).contribute_to_class(ModelWithLongField, long_field_name)
|
|
|
|
models.CharField(max_length=11, db_column='vlmn').contribute_to_class(ModelWithLongField, long_field_name2)
|
|
|
|
|
|
|
|
errors = ModelWithLongField.check()
|
|
|
|
|
|
|
|
# Error because of the field with long name added to the model
|
|
|
|
# without specifying db_column
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
'Autogenerated column name too long for field "%s". '
|
2014-06-10 20:04:19 +08:00
|
|
|
'Maximum length is "%s" for database "%s".'
|
2015-02-09 21:53:58 +08:00
|
|
|
% (long_field_name, self.max_column_name_length, self.column_limit_db_alias),
|
2014-06-10 20:04:19 +08:00
|
|
|
hint="Set the column name manually using 'db_column'.",
|
|
|
|
obj=ModelWithLongField,
|
|
|
|
id='models.E018',
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-02-08 05:34:56 +08:00
|
|
|
def test_including_separator(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
some__field = models.IntegerField()
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
|
|
|
'Field names must not contain "__".',
|
|
|
|
obj=Model._meta.get_field('some__field'),
|
2014-03-03 18:18:39 +08:00
|
|
|
id='fields.E002',
|
2014-01-20 10:45:21 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-02-08 05:34:56 +08:00
|
|
|
def test_pk(self):
|
2014-01-20 10:45:21 +08:00
|
|
|
class Model(models.Model):
|
2014-02-08 05:34:56 +08:00
|
|
|
pk = models.IntegerField()
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 18:18:39 +08:00
|
|
|
"'pk' is a reserved word that cannot be used as a field name.",
|
2014-02-08 05:34:56 +08:00
|
|
|
obj=Model._meta.get_field('pk'),
|
2014-03-03 18:18:39 +08:00
|
|
|
id='fields.E003',
|
2014-02-08 05:34:56 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
|
2015-11-17 13:39:28 +08:00
|
|
|
@isolate_apps('invalid_models_tests')
|
|
|
|
class ShadowingFieldsTests(SimpleTestCase):
|
2014-02-08 05:34:56 +08:00
|
|
|
|
2015-08-26 01:37:32 +08:00
|
|
|
def test_field_name_clash_with_child_accessor(self):
|
|
|
|
class Parent(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Child(Parent):
|
|
|
|
child = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
errors = Child.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
|
|
|
"The field 'child' clashes with the field "
|
|
|
|
"'child' from model 'invalid_models_tests.parent'.",
|
|
|
|
obj=Child._meta.get_field('child'),
|
|
|
|
id='models.E006',
|
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-02-08 05:34:56 +08:00
|
|
|
def test_multiinheritance_clash(self):
|
|
|
|
class Mother(models.Model):
|
|
|
|
clash = models.IntegerField()
|
|
|
|
|
|
|
|
class Father(models.Model):
|
|
|
|
clash = models.IntegerField()
|
|
|
|
|
|
|
|
class Child(Mother, Father):
|
|
|
|
# Here we have two clashed: id (automatic field) and clash, because
|
|
|
|
# both parents define these fields.
|
|
|
|
pass
|
|
|
|
|
|
|
|
errors = Child.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"The field 'id' from parent model "
|
|
|
|
"'invalid_models_tests.mother' clashes with the field 'id' "
|
|
|
|
"from parent model 'invalid_models_tests.father'.",
|
2014-02-08 05:34:56 +08:00
|
|
|
obj=Child,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E005',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"The field 'clash' from parent model "
|
|
|
|
"'invalid_models_tests.mother' clashes with the field 'clash' "
|
|
|
|
"from parent model 'invalid_models_tests.father'.",
|
2014-02-08 05:34:56 +08:00
|
|
|
obj=Child,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E005',
|
2014-02-08 05:34:56 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
def test_inheritance_clash(self):
|
|
|
|
class Parent(models.Model):
|
|
|
|
f_id = models.IntegerField()
|
|
|
|
|
|
|
|
class Target(models.Model):
|
|
|
|
# This field doesn't result in a clash.
|
|
|
|
f_id = models.IntegerField()
|
|
|
|
|
|
|
|
class Child(Parent):
|
|
|
|
# This field clashes with parent "f_id" field.
|
2015-07-22 22:43:21 +08:00
|
|
|
f = models.ForeignKey(Target, models.CASCADE)
|
2014-02-08 05:34:56 +08:00
|
|
|
|
|
|
|
errors = Child.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"The field 'f' clashes with the field 'f_id' "
|
|
|
|
"from model 'invalid_models_tests.parent'.",
|
2014-02-08 05:34:56 +08:00
|
|
|
obj=Child._meta.get_field('f'),
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E006',
|
2014-02-08 05:34:56 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2015-01-30 17:40:25 +08:00
|
|
|
def test_multigeneration_inheritance(self):
|
|
|
|
class GrandParent(models.Model):
|
|
|
|
clash = models.IntegerField()
|
|
|
|
|
|
|
|
class Parent(GrandParent):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Child(Parent):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class GrandChild(Child):
|
|
|
|
clash = models.IntegerField()
|
|
|
|
|
|
|
|
errors = GrandChild.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
|
|
|
"The field 'clash' clashes with the field 'clash' "
|
|
|
|
"from model 'invalid_models_tests.grandparent'.",
|
|
|
|
obj=GrandChild._meta.get_field('clash'),
|
|
|
|
id='models.E006',
|
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-02-08 05:34:56 +08:00
|
|
|
def test_id_clash(self):
|
|
|
|
class Target(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Model(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
fk = models.ForeignKey(Target, models.CASCADE)
|
2014-02-08 05:34:56 +08:00
|
|
|
fk_id = models.IntegerField()
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"The field 'fk_id' clashes with the field 'fk' from model "
|
|
|
|
"'invalid_models_tests.model'.",
|
2014-02-08 05:34:56 +08:00
|
|
|
obj=Model._meta.get_field('fk_id'),
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E006',
|
2014-02-08 05:34:56 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
|
2015-11-17 13:39:28 +08:00
|
|
|
@isolate_apps('invalid_models_tests')
|
|
|
|
class OtherModelTests(SimpleTestCase):
|
2014-02-08 05:34:56 +08:00
|
|
|
|
|
|
|
def test_unique_primary_key(self):
|
|
|
|
invalid_id = models.IntegerField(primary_key=False)
|
|
|
|
|
|
|
|
class Model(models.Model):
|
|
|
|
id = invalid_id
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"'id' can only be used as a field name if the field also sets "
|
|
|
|
"'primary_key=True'.",
|
2014-02-08 05:34:56 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E004',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
def test_ordering_non_iterable(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
ordering = "missing_field"
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"'ordering' must be a tuple or list "
|
|
|
|
"(even if you want to order by only one field).",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E014',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2015-03-17 22:42:53 +08:00
|
|
|
def test_just_ordering_no_errors(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
order = models.PositiveIntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['order']
|
|
|
|
|
2015-03-22 11:30:21 +08:00
|
|
|
self.assertEqual(Model.check(), [])
|
2015-03-17 22:42:53 +08:00
|
|
|
|
|
|
|
def test_just_order_with_respect_to_no_errors(self):
|
|
|
|
class Question(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Answer(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
question = models.ForeignKey(Question, models.CASCADE)
|
2015-03-17 22:42:53 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
order_with_respect_to = 'question'
|
|
|
|
|
2015-03-22 11:30:21 +08:00
|
|
|
self.assertEqual(Answer.check(), [])
|
2015-03-17 22:42:53 +08:00
|
|
|
|
|
|
|
def test_ordering_with_order_with_respect_to(self):
|
|
|
|
class Question(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Answer(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
question = models.ForeignKey(Question, models.CASCADE)
|
2015-03-17 22:42:53 +08:00
|
|
|
order = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
order_with_respect_to = 'question'
|
|
|
|
ordering = ['order']
|
|
|
|
|
|
|
|
errors = Answer.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
|
|
|
"'ordering' and 'order_with_respect_to' cannot be used together.",
|
|
|
|
obj=Answer,
|
|
|
|
id='models.E021',
|
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-07-08 17:24:08 +08:00
|
|
|
def test_non_valid(self):
|
|
|
|
class RelationModel(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Model(models.Model):
|
|
|
|
relation = models.ManyToManyField(RelationModel)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['relation']
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
|
|
|
"'ordering' refers to the non-existent field 'relation'.",
|
|
|
|
obj=Model,
|
|
|
|
id='models.E015',
|
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-01-20 10:45:21 +08:00
|
|
|
def test_ordering_pointing_to_missing_field(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
ordering = ("missing_field",)
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"'ordering' refers to the non-existent field 'missing_field'.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Model,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E015',
|
2014-01-20 10:45:21 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
2014-05-27 23:48:50 +08:00
|
|
|
def test_ordering_pointing_to_missing_foreignkey_field(self):
|
|
|
|
# refs #22711
|
|
|
|
|
|
|
|
class Model(models.Model):
|
|
|
|
missing_fk_field = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ("missing_fk_field_id",)
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
|
|
|
"'ordering' refers to the non-existent field 'missing_fk_field_id'.",
|
|
|
|
obj=Model,
|
|
|
|
id='models.E015',
|
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
def test_ordering_pointing_to_existing_foreignkey_field(self):
|
|
|
|
# refs #22711
|
|
|
|
|
|
|
|
class Parent(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Child(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey(Parent, models.CASCADE)
|
2014-05-27 23:48:50 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ("parent_id",)
|
|
|
|
|
|
|
|
self.assertFalse(Child.check())
|
|
|
|
|
2014-01-20 10:45:21 +08:00
|
|
|
@override_settings(TEST_SWAPPED_MODEL_BAD_VALUE='not-a-model')
|
|
|
|
def test_swappable_missing_app_name(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
swappable = 'TEST_SWAPPED_MODEL_BAD_VALUE'
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2014-03-03 15:35:42 +08:00
|
|
|
"'TEST_SWAPPED_MODEL_BAD_VALUE' is not of the form 'app_label.app_name'.",
|
|
|
|
id='models.E001',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
@override_settings(TEST_SWAPPED_MODEL_BAD_MODEL='not_an_app.Target')
|
|
|
|
def test_swappable_missing_app(self):
|
|
|
|
class Model(models.Model):
|
|
|
|
class Meta:
|
|
|
|
swappable = 'TEST_SWAPPED_MODEL_BAD_MODEL'
|
|
|
|
|
|
|
|
errors = Model.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"'TEST_SWAPPED_MODEL_BAD_MODEL' references 'not_an_app.Target', "
|
|
|
|
'which has not been installed, or is abstract.',
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E002',
|
2014-01-20 10:45:21 +08:00
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
|
|
|
|
|
|
|
def test_two_m2m_through_same_relationship(self):
|
|
|
|
class Person(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Group(models.Model):
|
2016-04-08 10:04:45 +08:00
|
|
|
primary = models.ManyToManyField(Person, through="Membership", related_name="primary")
|
|
|
|
secondary = models.ManyToManyField(Person, through="Membership", related_name="secondary")
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
class Membership(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
person = models.ForeignKey(Person, models.CASCADE)
|
|
|
|
group = models.ForeignKey(Group, models.CASCADE)
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
errors = Group.check()
|
|
|
|
expected = [
|
|
|
|
Error(
|
2015-02-09 21:53:58 +08:00
|
|
|
"The model has two many-to-many relations through "
|
|
|
|
"the intermediate model 'invalid_models_tests.Membership'.",
|
2014-01-20 10:45:21 +08:00
|
|
|
obj=Group,
|
2014-03-03 15:35:42 +08:00
|
|
|
id='models.E003',
|
2014-01-20 10:45:21 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
self.assertEqual(errors, expected)
|
2016-04-23 00:59:41 +08:00
|
|
|
|
|
|
|
def test_missing_parent_link(self):
|
|
|
|
with warnings.catch_warnings(record=True) as warns:
|
|
|
|
warnings.simplefilter('always')
|
|
|
|
|
|
|
|
class Place(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class ParkingLot(Place):
|
|
|
|
# In lieu of any other connector, an existing OneToOneField will be
|
|
|
|
# promoted to the primary key.
|
|
|
|
parent = models.OneToOneField(Place, models.CASCADE)
|
|
|
|
|
|
|
|
self.assertEqual(len(warns), 1)
|
|
|
|
msg = str(warns[0].message)
|
|
|
|
self.assertEqual(
|
|
|
|
msg,
|
|
|
|
'Add parent_link=True to invalid_models_tests.ParkingLot.parent '
|
|
|
|
'as an implicit link is deprecated.'
|
|
|
|
)
|
|
|
|
self.assertEqual(ParkingLot._meta.pk.name, 'parent')
|
2016-06-04 03:55:30 +08:00
|
|
|
|
|
|
|
def test_m2m_table_name_clash(self):
|
|
|
|
class Foo(models.Model):
|
|
|
|
bar = models.ManyToManyField('Bar', db_table='myapp_bar')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = 'myapp_foo'
|
|
|
|
|
|
|
|
class Bar(models.Model):
|
|
|
|
class Meta:
|
|
|
|
db_table = 'myapp_bar'
|
|
|
|
|
|
|
|
self.assertEqual(Foo.check(), [
|
|
|
|
Error(
|
|
|
|
"The field's intermediary table 'myapp_bar' clashes with the "
|
|
|
|
"table name of 'invalid_models_tests.Bar'.",
|
|
|
|
obj=Foo._meta.get_field('bar'),
|
|
|
|
id='fields.E340',
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_m2m_field_table_name_clash(self):
|
|
|
|
class Foo(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Bar(models.Model):
|
|
|
|
foos = models.ManyToManyField(Foo, db_table='clash')
|
|
|
|
|
|
|
|
class Baz(models.Model):
|
|
|
|
foos = models.ManyToManyField(Foo, db_table='clash')
|
|
|
|
|
|
|
|
self.assertEqual(Bar.check() + Baz.check(), [
|
|
|
|
Error(
|
|
|
|
"The field's intermediary table 'clash' clashes with the "
|
|
|
|
"table name of 'invalid_models_tests.Baz.foos'.",
|
|
|
|
obj=Bar._meta.get_field('foos'),
|
|
|
|
id='fields.E340',
|
|
|
|
),
|
|
|
|
Error(
|
|
|
|
"The field's intermediary table 'clash' clashes with the "
|
|
|
|
"table name of 'invalid_models_tests.Bar.foos'.",
|
|
|
|
obj=Baz._meta.get_field('foos'),
|
|
|
|
id='fields.E340',
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_m2m_autogenerated_table_name_clash(self):
|
|
|
|
class Foo(models.Model):
|
|
|
|
class Meta:
|
|
|
|
db_table = 'bar_foos'
|
|
|
|
|
|
|
|
class Bar(models.Model):
|
|
|
|
# The autogenerated `db_table` will be bar_foos.
|
|
|
|
foos = models.ManyToManyField(Foo)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = 'bar'
|
|
|
|
|
|
|
|
self.assertEqual(Bar.check(), [
|
|
|
|
Error(
|
|
|
|
"The field's intermediary table 'bar_foos' clashes with the "
|
|
|
|
"table name of 'invalid_models_tests.Foo'.",
|
|
|
|
obj=Bar._meta.get_field('foos'),
|
|
|
|
id='fields.E340',
|
|
|
|
)
|
|
|
|
])
|
2016-08-17 02:23:30 +08:00
|
|
|
|
2016-09-10 06:52:34 +08:00
|
|
|
def test_m2m_unmanaged_shadow_models_not_checked(self):
|
|
|
|
class A1(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class C1(models.Model):
|
|
|
|
mm_a = models.ManyToManyField(A1, db_table='d1')
|
|
|
|
|
|
|
|
# Unmanaged models that shadow the above models. Reused table names
|
|
|
|
# shouldn't be flagged by any checks.
|
|
|
|
class A2(models.Model):
|
|
|
|
class Meta:
|
|
|
|
managed = False
|
|
|
|
|
|
|
|
class C2(models.Model):
|
|
|
|
mm_a = models.ManyToManyField(A2, through='Intermediate')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
managed = False
|
|
|
|
|
|
|
|
class Intermediate(models.Model):
|
|
|
|
a2 = models.ForeignKey(A2, models.CASCADE, db_column='a1_id')
|
|
|
|
c2 = models.ForeignKey(C2, models.CASCADE, db_column='c1_id')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = 'd1'
|
|
|
|
managed = False
|
|
|
|
|
|
|
|
self.assertEqual(C1.check(), [])
|
|
|
|
self.assertEqual(C2.check(), [])
|
|
|
|
|
2016-08-17 02:23:30 +08:00
|
|
|
@isolate_apps('django.contrib.auth', kwarg_name='apps')
|
|
|
|
def test_lazy_reference_checks(self, apps):
|
|
|
|
class DummyModel(models.Model):
|
|
|
|
author = models.ForeignKey('Author', models.CASCADE)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
app_label = 'invalid_models_tests'
|
|
|
|
|
|
|
|
class DummyClass(object):
|
|
|
|
def __call__(self, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def dummy_method(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def dummy_function(*args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
apps.lazy_model_operation(dummy_function, ('auth', 'imaginarymodel'))
|
|
|
|
apps.lazy_model_operation(dummy_function, ('fanciful_app', 'imaginarymodel'))
|
|
|
|
|
|
|
|
post_init.connect(dummy_function, sender='missing-app.Model', apps=apps)
|
|
|
|
post_init.connect(DummyClass(), sender='missing-app.Model', apps=apps)
|
|
|
|
post_init.connect(DummyClass().dummy_method, sender='missing-app.Model', apps=apps)
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
Error(
|
|
|
|
"%r contains a lazy reference to auth.imaginarymodel, "
|
|
|
|
"but app 'auth' doesn't provide model 'imaginarymodel'." % dummy_function,
|
|
|
|
obj=dummy_function,
|
|
|
|
id='models.E022',
|
|
|
|
),
|
|
|
|
Error(
|
|
|
|
"%r contains a lazy reference to fanciful_app.imaginarymodel, "
|
|
|
|
"but app 'fanciful_app' isn't installed." % dummy_function,
|
|
|
|
obj=dummy_function,
|
|
|
|
id='models.E022',
|
|
|
|
),
|
|
|
|
Error(
|
|
|
|
"An instance of class 'DummyClass' was connected to "
|
|
|
|
"the 'post_init' signal with a lazy reference to the sender "
|
|
|
|
"'missing-app.model', but app 'missing-app' isn't installed.",
|
|
|
|
hint=None,
|
|
|
|
obj='invalid_models_tests.test_models',
|
|
|
|
id='signals.E001',
|
|
|
|
),
|
|
|
|
Error(
|
|
|
|
"Bound method 'DummyClass.dummy_method' was connected to the "
|
|
|
|
"'post_init' signal with a lazy reference to the sender "
|
|
|
|
"'missing-app.model', but app 'missing-app' isn't installed.",
|
|
|
|
hint=None,
|
|
|
|
obj='invalid_models_tests.test_models',
|
|
|
|
id='signals.E001',
|
|
|
|
),
|
|
|
|
Error(
|
|
|
|
"The field invalid_models_tests.DummyModel.author was declared "
|
|
|
|
"with a lazy reference to 'invalid_models_tests.author', but app "
|
|
|
|
"'invalid_models_tests' isn't installed.",
|
|
|
|
hint=None,
|
|
|
|
obj=DummyModel.author.field,
|
|
|
|
id='fields.E307',
|
|
|
|
),
|
|
|
|
Error(
|
|
|
|
"The function 'dummy_function' was connected to the 'post_init' "
|
|
|
|
"signal with a lazy reference to the sender "
|
|
|
|
"'missing-app.model', but app 'missing-app' isn't installed.",
|
|
|
|
hint=None,
|
|
|
|
obj='invalid_models_tests.test_models',
|
|
|
|
id='signals.E001',
|
|
|
|
),
|
|
|
|
]
|
|
|
|
self.assertEqual(_check_lazy_references(apps), expected)
|