Fixed #23857 -- Fixed admin crash with "save as new" and deleting inline.
Thanks amarandon for the report.
This commit is contained in:
parent
267a1dcd9b
commit
c7a19f4203
|
@ -1858,6 +1858,8 @@ class InlineModelAdmin(BaseModelAdmin):
|
||||||
if self.cleaned_data.get(DELETION_FIELD_NAME, False):
|
if self.cleaned_data.get(DELETION_FIELD_NAME, False):
|
||||||
using = router.db_for_write(self._meta.model)
|
using = router.db_for_write(self._meta.model)
|
||||||
collector = NestedObjects(using=using)
|
collector = NestedObjects(using=using)
|
||||||
|
if self.instance.pk is None:
|
||||||
|
return
|
||||||
collector.collect([self.instance])
|
collector.collect([self.instance])
|
||||||
if collector.protected:
|
if collector.protected:
|
||||||
objs = []
|
objs = []
|
||||||
|
|
|
@ -121,3 +121,6 @@ Bugfixes
|
||||||
model (:ticket:`23956`).
|
model (:ticket:`23956`).
|
||||||
|
|
||||||
* Fixed a crash when a ``MultiValueField`` has invalid data (:ticket:`23674`).
|
* Fixed a crash when a ``MultiValueField`` has invalid data (:ticket:`23674`).
|
||||||
|
|
||||||
|
* Fixed a crash in the admin when using "Save as new" and also deleting a
|
||||||
|
related inline (:ticket:`23857`).
|
||||||
|
|
|
@ -250,6 +250,23 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
||||||
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
|
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
|
||||||
self.assertEqual(response.status_code, 302) # redirect somewhere
|
self.assertEqual(response.status_code, 302) # redirect somewhere
|
||||||
|
|
||||||
|
def test_edit_save_as_delete_inline(self):
|
||||||
|
"""
|
||||||
|
Should be able to "Save as new" while also deleting an inline.
|
||||||
|
"""
|
||||||
|
post_data = self.inline_post_data.copy()
|
||||||
|
post_data.update({
|
||||||
|
'_saveasnew': 'Save+as+new',
|
||||||
|
"article_set-1-section": "1",
|
||||||
|
"article_set-2-section": "1",
|
||||||
|
"article_set-2-DELETE": "1",
|
||||||
|
"article_set-3-section": "1",
|
||||||
|
})
|
||||||
|
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
# started with 3 articles, one was deleted.
|
||||||
|
self.assertEqual(Section.objects.latest('id').article_set.count(), 2)
|
||||||
|
|
||||||
def test_change_list_sorting_callable(self):
|
def test_change_list_sorting_callable(self):
|
||||||
"""
|
"""
|
||||||
Ensure we can sort on a list_display field that is a callable
|
Ensure we can sort on a list_display field that is a callable
|
||||||
|
|
Loading…
Reference in New Issue