modlinltd/django-advanced-filters

'AdvancedFilterQueryForm' object has no attribute 'cleaned_data'

Closed this issue ยท 18 comments

Describe the bug

Trying to create any new filter leads to AdvancedFilterQueryForm object has no attribute cleaned_data error.

Steps to reproduce

  • Have Django 3.2.0 installed
  • Try creating a filter

Expected behaviour

You should be able to create a filter

Details

  • OS: Windows 10/Alpine Linux v3.13
  • Python version 3.7/3.8
  • Django version 3.2.0
  • django-advanced-filters version 1.3.0
  • Browser Chrome

@DuSheridan Did you solve it?, I am facing the same problem

@Nader-Blnk I've side-stepped the issue by downgrading django to 3.1.3, haven't really looked into it since.

Looks like it's broken starting after merging this PR
django/django#13627

I'm facing the same issue, with django 3.2.2

same problem :(

Same problem :(

As i can see, this issue starting from Django 3.2. I can`t reprodusing it on 3.1.13(last version of 3.1 branch).,
ok, as first very dirty solution, we can override clean method of AdvancedFilterForm class,
inside your admin.py

from advanced_filters import forms as adv_forms
class MyAdvancedFilterForm(adv_forms.AdvancedFilterForm):
    def clean(self):
        for form in self.fields_formset:
            if not form.is_valid():
                form.cleaned_data = {'field':'id', 'DELETE': True}
        return super().clean()
class MyAdminAdvancedFiltersMixin(AdminAdvancedFiltersMixin):
    advanced_filter_form = MyAdvancedFilterForm

# as usually
@admin.register(MyModel)
class MyModelAdmin(MyAdminAdvancedFiltersMixin, admin.ModelAdmin ):
    list_display = ('__str__', 'id', 'title', .....)
    advanced_filter_fields = (
        'id',
        'title'
        ....
    )

It`s work's, almost as expected, but it's probably broke editing form... So, you can create filters, but you can't edit it.
problem of this issue: formset try validete default emty_form. This form always empty, so is_bound prorerty - False. Validation - fail, form do not create cleaned_data...

Hope, founders fix it. django-advanced-filters is really useful extension.

hzung commented

@urfinorg I can't edit the filter either. Is there any way to fix it?

hzung commented

I finally fix the above issue by adding these codes in the source and installing the extension by

cd django-advanced-filters
python3 setup.py install

Thanks to the code of @urfinorg

Here is the PR: https://github.com/modlinltd/django-advanced-filters/pull/153/files
I can create a new filter or update the filter now. I don't know if there is any drawback to this fix. But at least It works for now

This seems to be fixed in the develop branch?!
@DuSheridan any plans for a PyPI release that fixes this?

Do you fix it?

Recent maintainers @asfaltboy and @hugovk , this issue prevents the use of django-advanced-filters on Django 3.2+.

My understanding is that a fix has been merged to the develop branch but no release has been issued to PyPI with the fix. Any chance one of you could cut a release so that django-advanced-filters can be used on modern Django versions?

@davidfstr Hi! I'm not a maintainer here, just contributed a PR :)

Only @asfaltboy is listed as the PyPI maintainer https://pypi.org/project/django-advanced-filters/, hopefully he can make a release soon.

Thanks for the kind reminder, since this version contains a breaking change (dropping support for older Python/Django versions), it's released as 2.0.0 on pypi.

Hi @asfaltboy ,

Good news. May you also take a look at related PR for that issue? #153

Maybe we can merge it and release to PyPI also?

@DmytroLitvinov we're saying the validation issue is not fixed in 2.0 ? Can you provide some more details on what used to happen and what doesn't happen now? Would it previously let you create a filter without any value in the value field, or would it raise a validation error, and now doesn't?

Hi @asfaltboy ,
It was reported by my colleague so I just let you know about taking a look. In our case we reused library for our own needs.

I wasn't able to reproduce this particular issue as described above in 2.0. I'm going to go ahead and close the issue. If there are any concerns, please let me know. If there's still some issue, kindly provide step-by-step instructions on how to reproduce the issue. And please forgive me If I missed something obvious