diff options
| author | saJaeHyukc <wogur981208@gmail.com> | 2025-03-12 17:39:34 +0900 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-03-28 12:37:57 +0100 |
| commit | c1a4fccf53437e480c42648f67277fb7e63ed4ab (patch) | |
| tree | bf315b7c9fbf1f4a61ad15a7c9a64d84125eaaf0 /tests/invalid_models_tests | |
| parent | a0f50c2a483678d31bd1ad6f08fd3a0b8399e27b (diff) | |
Fixed #36239 -- Fixed a crash in ManyToManyField.through_fields check when to model is invalid.
Signed-off-by: saJaeHyukc <wogur981208@gmail.com>
Diffstat (limited to 'tests/invalid_models_tests')
| -rw-r--r-- | tests/invalid_models_tests/test_relative_fields.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_relative_fields.py b/tests/invalid_models_tests/test_relative_fields.py index 4167e0712a..5a791d1fcc 100644 --- a/tests/invalid_models_tests/test_relative_fields.py +++ b/tests/invalid_models_tests/test_relative_fields.py @@ -2185,3 +2185,45 @@ class M2mThroughFieldsTests(SimpleTestCase): ), ], ) + + def test_invalid_to_argument_with_through(self): + class Foo(models.Model): + pass + + class Bar(models.Model): + foos = models.ManyToManyField( + to="Fo", + through="FooBar", + through_fields=("bar", "foo"), + ) + + class FooBar(models.Model): + foo = models.ForeignKey("Foo", on_delete=models.CASCADE) + bar = models.ForeignKey("Bar", on_delete=models.CASCADE) + + field = Bar._meta.get_field("foos") + + self.assertEqual( + field.check(from_model=Bar), + [ + Error( + "Field defines a relation with model 'Fo', " + "which is either not installed, or is abstract.", + obj=field, + id="fields.E300", + ), + Error( + "The model is used as an intermediate model by " + "'invalid_models_tests.Bar.foos', " + "but it does not have a foreign key to 'Bar' " + "or 'invalid_models_tests.Fo'.", + obj=FooBar, + id="fields.E336", + ), + Error( + "'FooBar.foo' is not a foreign key to 'Fo'.", + obj=field, + id="fields.E339", + ), + ], + ) |
