#17636: InMemoryUploadedFile object has no attribute _committed
--------------------------------------+--------------------
Reporter: lwarx | Owner: nobody
Type: Uncategorized | Status: new
Component: File uploads/storage | Version: 1.3
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
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/base.py" in
get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py"
in wrapper
307. return self.admin_site.admin_view(view)(*args,
**kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in
_wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py"
in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in
inner
197. return view(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in
_wrapper
28. return bound_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in
_wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in
bound_func
24. return func(self, *args2, **kwargs2)
File "/Library/Python/2.7/site-packages/django/db/transaction.py" in inner
217. res = func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py"
in add_view
882. self.save_model(request, new_object, form,
change=False)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py"
in save_model
665. obj.save()
File "/Library/Python/2.7/site-packages/django/db/models/base.py" 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/base.py" 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/files.py"
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/17636>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.