mirror of
https://github.com/django/django.git
synced 2025-10-29 16:46:11 +00:00
[3.2.x] Fixed #32332 -- Fixed loss of parent with non-numeric pk when saving child after parent.
Follow up to519016e5f2. Backport of7cba92ec55from master
This commit is contained in:
committed by
Mariusz Felisiak
parent
7d65889345
commit
b36beec208
@@ -7,9 +7,9 @@ from django.test import TestCase
|
||||
from django.utils.translation import gettext_lazy
|
||||
|
||||
from .models import (
|
||||
Article, Category, Child, ChildNullableParent, City, Country, District,
|
||||
First, Parent, Record, Relation, Reporter, School, Student, Third,
|
||||
ToFieldChild,
|
||||
Article, Category, Child, ChildNullableParent, ChildStringPrimaryKeyParent,
|
||||
City, Country, District, First, Parent, ParentStringPrimaryKey, Record,
|
||||
Relation, Reporter, School, Student, Third, ToFieldChild,
|
||||
)
|
||||
|
||||
|
||||
@@ -549,6 +549,16 @@ class ManyToOneTests(TestCase):
|
||||
self.assertEqual(child.parent, parent)
|
||||
self.assertEqual(child.parent_id, parent.name)
|
||||
|
||||
def test_save_fk_after_parent_with_non_numeric_pk_set_on_child(self):
|
||||
parent = ParentStringPrimaryKey()
|
||||
child = ChildStringPrimaryKeyParent(parent=parent)
|
||||
child.parent.name = 'jeff'
|
||||
parent.save()
|
||||
child.save()
|
||||
child.refresh_from_db()
|
||||
self.assertEqual(child.parent, parent)
|
||||
self.assertEqual(child.parent_id, parent.name)
|
||||
|
||||
def test_fk_to_bigautofield(self):
|
||||
ch = City.objects.create(name='Chicago')
|
||||
District.objects.create(city=ch, name='Far South')
|
||||
|
||||
Reference in New Issue
Block a user