mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed 31207 -- Prevented references to non-local remote fields in ForeignKey.to_field.
Thanks Simon Charette for the initial patch and review.
This commit is contained in:
parent
4e8d89020c
commit
a97111eabf
3 changed files with 37 additions and 0 deletions
|
@ -2,6 +2,7 @@ from decimal import Decimal
|
|||
|
||||
from django.apps import apps
|
||||
from django.core import checks
|
||||
from django.core.exceptions import FieldError
|
||||
from django.db import models
|
||||
from django.test import TestCase, skipIfDBFeature
|
||||
from django.test.utils import isolate_apps
|
||||
|
@ -128,3 +129,21 @@ class ForeignKeyTests(TestCase):
|
|||
|
||||
with self.assertRaisesMessage(ValueError, 'Cannot resolve output_field'):
|
||||
Foo._meta.get_field('bar').get_col('alias')
|
||||
|
||||
@isolate_apps('model_fields')
|
||||
def test_non_local_to_field(self):
|
||||
class Parent(models.Model):
|
||||
key = models.IntegerField(unique=True)
|
||||
|
||||
class Child(Parent):
|
||||
pass
|
||||
|
||||
class Related(models.Model):
|
||||
child = models.ForeignKey(Child, on_delete=models.CASCADE, to_field='key')
|
||||
|
||||
msg = (
|
||||
"'model_fields.Related.child' refers to field 'key' which is not "
|
||||
"local to model 'model_fields.Child'."
|
||||
)
|
||||
with self.assertRaisesMessage(FieldError, msg):
|
||||
Related._meta.get_field('child').related_fields
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue