Django 'bool' Object has no attribute '_Committed'

Asked

Viewed 315 times

7

I have a field of sorts FileField and when I try to delete the contents of it, returns me this error message:

bool' Object has no attribute '_Committed'

To make the upload works normally, the problem is only when I try to remove the file that was sent.

try:
    profile = request.user.get_profile()
    company = profile.company
except ObjectDoesNotExist:
    raise Http404    


if request.method == 'POST':
   data = request.POST
   profile_form = EditUserProfileForm(data=data)
   company_form = EditCompanyForm(data=data, files=request.FILES)

  if profile_form.is_valid() and company_form.is_valid():
     profile_form.save(profile)
     company_form.save(company)
     messages.info(request, 'Dados atualizados com sucesso.')
     return HttpResponseRedirect('')
 else:
    profile_form.save(profile)
    company_form.save(company)  #Erro Ao tentar salvar o company.
    messages.info(request, 'Dados atualizados com sucesso.')
    return HttpResponseRedirect('')

Edit: the full traceback

Traceback:
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
      111.response = callback(request, *callback_args, **callback_kwargs)
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
      23.                 return view_func(request, *args, **kwargs)
    File "/home/vanderson/Sites/cargo-br/cargobr/../cargobr/apps/accounts/views.py" in edit
      407.                     company_form.save(company)
    File "/home/vanderson/Sites/cargo-br/cargobr/../cargobr/apps/accounts/forms.py" in save
      147.         company.save()
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.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 "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/django/db/models/base.py" in save_base
      484.             signals.pre_save.send(sender=origin, instance=self, raw=raw, using=using)
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
      172.             response = receiver(signal=self, sender=sender, **named)
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/easy_thumbnails/signal_handlers.py" in find_uncommitted_filefields
      20.             if not getattr(instance, field.name)._committed:
    
    Exception Type: AttributeError at /editar-cadastro/
    Exception Value: 'bool' object has no attribute '_committed'

Editcompanyform:

class EditCompanyForm(CompanyForm):

    class Meta:
        model = accounts.models.Company
        exclude = ('verified', 'rating')

    
    def save(self, company):
        company.insurance_policy = self.cleaned_data['insurance_policy']
        company.save()
        return company
  • What is the last line of your code that runs before the error. I couldn’t figure out where this error might come from just with the code you posted.

  • It enters Else and the last line executed before the error is profile_form.save(profile)

1 answer

3

The problem seems to be that you have overwritten the method save() of Form without calling the save() original. Try trading for this code:

def save(self, company):
    company = super(EditCompanyForm, self).save(
        commit=False)
    company.insurance_policy = self.cleaned_data['insurance_policy']
    company.save(commit=True)
    return company

Browser other questions tagged

You are not signed in. Login or sign up in order to post.