File tree 2 files changed +20
-5
lines changed
2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,15 @@ def _process_picture(
33
33
old = old or []
34
34
storage = utils .reconstruct (* storage )
35
35
if new :
36
- with storage .open (file_name ) as fs :
37
- with Image .open (fs ) as img :
38
- for picture in new :
39
- picture = utils .reconstruct (* picture )
40
- picture .save (img )
36
+ try :
37
+ with storage .open (file_name ) as fs :
38
+ with Image .open (fs ) as img :
39
+ for picture in new :
40
+ picture = utils .reconstruct (* picture )
41
+ picture .save (img )
42
+ except FileNotFoundError :
43
+ # The file no longer exists (for example, because it was deleted or replaced).
44
+ return
41
45
42
46
for picture in old :
43
47
picture = utils .reconstruct (* picture )
Original file line number Diff line number Diff line change @@ -22,5 +22,16 @@ def test_process_picture__file_cannot_be_reopened(image_upload_file):
22
22
)
23
23
24
24
25
+ @pytest .mark .django_db
26
+ def test_process_picture__file_missing (image_upload_file ):
27
+ obj = SimpleModel .objects .create (picture = image_upload_file )
28
+ obj .picture .file .delete ()
29
+ tasks ._process_picture (
30
+ obj .picture .storage .deconstruct (),
31
+ obj .picture .name ,
32
+ new = [i .deconstruct () for i in obj .picture .get_picture_files_list ()],
33
+ )
34
+
35
+
25
36
def test_noop ():
26
37
tasks .noop () # does nothing
You can’t perform that action at this time.
0 commit comments