django-import-export / django-import-export

Django application and library for importing and exporting data with admin integration.

Home Page:https://django-import-export.readthedocs.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

4.0 compatiblity with AutoSlugField - unexpected keyword argument 'allow_blank'

bufke opened this issue · comments

Describe the bug

It appears that 4.0 errors when used with AutoSlugField from django-extensions.

To Reproduce

class Foo(models.Model)
    slug = AutoSlugField(populate_from=["name"], max_length=50)

class FooResource(resources.ModelResource):
    class Meta:
        model = Foo
File "/usr/local/lib/python3.12/site-packages/import_export/declarative.py", line 100, in __new__
  field = new_class.field_from_django_field(f.name, f, readonly=False)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/import_export/resources.py", line 1279, in field_from_django_field
  widget=FieldWidget(**widget_kwargs),
TypeError: Widget.__init__() got an unexpected keyword argument 'allow_blank'

Versions (please complete the following information):

  • Django Import Export: 4.0
  • Python 3.12
  • Django 5.0

Expected behavior

I'm not sure if this can be in scope, but django extensions is fairly popular and has worked prior. I'd expect an upgrade to not break it. I'm not sure how to work around id.

It works fine with 3.x or by replacing the AutoSlugField with a CharField.

Thanks for raising. This is a valid bug.

This is occurring because SlugField is identified as a subclass of CharField and the appropriate kwargs are derived for CharWidget. However, the widget type is the default of Widget so the process crashes when passed the CharWidget kwargs.