Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0 compatiblity with AutoSlugField - unexpected keyword argument 'allow_blank' #1804

Closed
bufke opened this issue Apr 30, 2024 · 1 comment · Fixed by #1805
Closed

4.0 compatiblity with AutoSlugField - unexpected keyword argument 'allow_blank' #1804

bufke opened this issue Apr 30, 2024 · 1 comment · Fixed by #1805
Assignees
Labels

Comments

@bufke
Copy link

bufke commented Apr 30, 2024

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.

@bufke bufke added the bug label Apr 30, 2024
@matthewhegarty
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants