File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1858,6 +1858,8 @@ def hand_clean_DELETE(self):
1858
1858
if self .cleaned_data .get (DELETION_FIELD_NAME , False ):
1859
1859
using = router .db_for_write (self ._meta .model )
1860
1860
collector = NestedObjects (using = using )
1861
+ if self .instance .pk is None :
1862
+ return
1861
1863
collector .collect ([self .instance ])
1862
1864
if collector .protected :
1863
1865
objs = []
Original file line number Diff line number Diff line change @@ -121,3 +121,6 @@ Bugfixes
121
121
model (:ticket:`23956`).
122
122
123
123
* 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`).
Original file line number Diff line number Diff line change @@ -250,6 +250,23 @@ def test_edit_save_as(self):
250
250
response = self .client .post ('/test_admin/%s/admin_views/section/1/' % self .urlbit , post_data )
251
251
self .assertEqual (response .status_code , 302 ) # redirect somewhere
252
252
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
+
253
270
def test_change_list_sorting_callable (self ):
254
271
"""
255
272
Ensure we can sort on a list_display field that is a callable
You can’t perform that action at this time.
0 commit comments