Opened 5 years ago

Last modified 5 years ago

#13750 new Bug

ImageField accessing height or width and then data results in "I/O operation on closed file"

Reported by: ROsborne Owned by: nobody
Component: File uploads/storage Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alex)

If you have a simple model with an ImageField, the following code will fail with a "I/O operation on closed file":

instance = MyClass.objects.get(...)
w = instance.image.width
h = instance.image.height
original = Image.open(instance.image)

The work around is to reopen the file:

instance = MyClass.objects.get(...)
w = instance.image.width
h = instance.image.height
instance.image.open()
original = Image.open(instance.image)

Note this is different than the issue of the 2nd read() returning empty strings for two reasons:

  1. You can not seek(0), the file is closed.
  1. Needing to reopen in this case is unexpected.

Change History (6)

comment:1 Changed 5 years ago by Alex

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Reformatted description. Next time please use preview and consult WikiFormatting.

comment:2 Changed 5 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by russellm

#13874 is a different presentation of the same problem.

comment:4 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

Note: See TracTickets for help on using tickets.
Back to Top