Opened 7 years ago

Closed 7 years ago

#17636 closed Uncategorized (invalid)

InMemoryUploadedFile object has no attribute _committed

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


Uploading any image to the following custom field leads to exception:

class ImageField(models.ImageField):
    __metaclass__ = models.SubfieldBase

This example is simplified as much as possible. In real project I want to store thumbnail directory path instead of full file path and use to_python/get_prep_value to do necessary transforms (according to the docs, SubfieldBase is required for to_python to work).

Traceback is below:

File "/Library/Python/2.7/site-packages/django/core/handlers/" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/" in wrapper
  307.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/" in _wrapped_view_func
  79.         response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/" in inner
  197.             return view(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/" in _wrapper
  28.             return bound_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/" in bound_func
  24.                 return func(self, *args2, **kwargs2)
File "/Library/Python/2.7/site-packages/django/db/" in inner
  217.                 res = func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/" in add_view
  882.                 self.save_model(request, new_object, form, change=False)
File "/Library/Python/2.7/site-packages/django/contrib/admin/" in save_model
File "/Library/Python/2.7/site-packages/django/db/models/" in save
  460.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/" in save_base
  543.                         for f in meta.local_fields if not isinstance(f, AutoField)]
File "/Library/Python/2.7/site-packages/django/db/models/fields/" in pre_save
  253.         if file and not file._committed:

Exception Type: AttributeError at /admin/db/testapp/imagetest/add/
Exception Value: 'InMemoryUploadedFile' object has no attribute '_committed'

I spent a lot of time trying to understand complex file class hierarchy (FileField, FieldFile, FileDescriptor, UploadedFile, File, storage), but now I'm stuck and not really sure if this a Django bug or error on my side. Please sorry for noise if the latter.

Change History (1)

comment:1 Changed 7 years ago by Łukasz Rekucki

Resolution: invalid
Status: newclosed

AFAIK, you should only use SubfieldBase if you're subclassing Field itself. See the notes on subclassing FileField ( for a better way to do what you want.

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