10000 Fixed #23857 -- Fixed admin crash with "save as new" and deleting inl… · alex-python/django@c7a19f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit c7a19f4

Browse files
committed
Fixed #23857 -- Fixed admin crash with "save as new" and deleting inline.
Thanks amarandon for the report.
1 parent 267a1dc commit c7a19f4

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

django/contrib/admin/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,8 @@ def hand_clean_DELETE(self):
18581858
if self.cleaned_data.get(DELETION_FIELD_NAME, False):
18591859
using = router.db_for_write(self._meta.model)
18601860
collector = NestedObjects(using=using)
1861+
if self.instance.pk is None:
1862+
return
18611863
collector.collect([self.instance])
18621864
if collector.protected:
18631865
objs = []

docs/releases/1.7.2.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,6 @@ Bugfixes
121121
model (:ticket:`23956`).
122122

123123
* Fixed a crash when a ``MultiValueField`` has invalid data (:ticket:`23674`).
124+
125+
* Fixed a crash in the admin when using "Save as new" and also deleting a
126+
related inline (:ticket:`23857`).

tests/admin_views/tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ def test_edit_save_as(self):
250250
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
251251
self.assertEqual(response.status_code, 302) # redirect somewhere
252252

253+
def test_edit_save_as_delete_inline(self):
254+
"""
255+
Should be able to "Save as new" while also deleting an inline.
256+
"""
257+
post_data = self.inline_post_data.copy()
258+
post_data.update({
259+
'_saveasnew': 'Save+as+new',
260+
"article_set-1-section": "1",
261+
"article_set-2-section": "1",
262+
"article_set-2-DELETE": "1",
263+
"article_set-3-section": "1",
264+
})
265+
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
266+
self.assertEqual(response.status_code, 302)
267+
# started with 3 articles, one was deleted.
268+
self.assertEqual(Section.objects.latest('id').article_set.count(), 2)
269+
253270
def test_change_list_sorting_callable(self):
254271
"""
255272
Ensure we can sort on a list_display field that is a callable

0 commit comments

Comments
 (0)
0