#30252: ImageField's to_python() stores reference to closed Image object
--------------------------------------+------------------------------------
     Reporter:  Felix Dreissig        |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Documentation         |                  Version:  2.1
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Felix Dreissig):

 Replying to [comment:5 Tim Graham]:
 > The original commit is 8b7347220f3d86b46f5f87270c6cdcb9960895fd. As you
 can see there, the non-image data attributes like `format`, `height`, and
 `width` are available without reopening the image.

 Yes. If I recall my analysis correctly, basically all attributes are
 accessible, while no methods are.

 > Does your purposed change affect performance?

 Since `open()` is a lazy operation in Pillow (image data is not loaded
 until accessed), I assume the performance impact would be negligible. I
 haven't run any measurements, though.

 Replying to [comment:6 Carlton Gibson]:
 > Just for your proposal: if we reopen the file, where are we closing it
 again?

 Fair point. Images themselves don't have to be closed in Pillow, but
 underlying file pointers do. So this should only be relevant if we have a
 temporary file path (no in-memory image data).

 According to the
 [https://pillow.readthedocs.io/en/stable/reference/open_files.html#file-
 handling Pillow docs on file handling], file pointers for single-frame
 images are automatically closed after `load()` has been called. However,
 as stated above, loading might not always happen. On top of that, multi-
 frame images are probably always problematic.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30252#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/061.ba0cf835e37e880313dd507bafc731aa%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to