[Django] #17636: InMemoryUploadedFile object has no attribute _committed

254 views
Skip to first unread message

Django

unread,
Feb 3, 2012, 4:06:11 PM2/3/12
to django-...@googlegroups.com
#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.

Django

unread,
Feb 4, 2012, 5:51:42 PM2/4/12
to django-...@googlegroups.com
#17636: InMemoryUploadedFile object has no attribute _committed
-------------------------------------+-------------------------------------
Reporter: lwarx | Owner: nobody
Type: Uncategorized | Status: closed
Component: File | Version: 1.3
uploads/storage | Resolution: invalid
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by lrekucki):

* status: new => closed
* needs_docs: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_better_patch: => 0


Comment:

AFAIK, you should only use {{{SubfieldBase}}} if you're subclassing
{{{Field}}} itself. See the notes on subclassing {{{FileField}}}
(https://docs.djangoproject.com/en/dev/howto/custom-model-
fields/#writing-a-filefield-subclass) for a better way to do what you
want.

--
Ticket URL: <https://code.djangoproject.com/ticket/17636#comment:1>

Reply all
Reply to author
Forward
0 new messages