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

allow_unicode should not be popped off the kwargs #64

Open
CaptainCuddleCube opened this issue Jan 29, 2020 · 2 comments
Open

allow_unicode should not be popped off the kwargs #64

CaptainCuddleCube opened this issue Jan 29, 2020 · 2 comments

Comments

@CaptainCuddleCube
Copy link

Currently, the django-autoslug sets self.allow_unicode to the kwargs value and it pops allow_unicode out the kwargs.

self.allow_unicode = kwargs.pop('allow_unicode', False)

Since SlugField has allow_unicode=False in its init kwargs, and then sets self.allow_unicode=allow_unicode, you get a situation where self.allow_unicode is always false.

The solution is to just remove the code where self.allow_unicode is set and the kwargs are popped off.

@devo-wm
Copy link

devo-wm commented Mar 22, 2021

Currently, the django-autoslug sets self.allow_unicode to the kwargs value and it pops allow_unicode out the kwargs.

self.allow_unicode = kwargs.pop('allow_unicode', False)

Since SlugField has allow_unicode=False in its init kwargs, and then sets self.allow_unicode=allow_unicode, you get a situation where self.allow_unicode is always false.

The solution is to just remove the code where self.allow_unicode is set and the kwargs are popped off.

Tried this locally and I actually ran into another error:

Traceback (most recent call last):
  File "~/Projects/project/./appname/manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "~/Projects/project/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "~/Projects/project/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "~/Projects/project/venv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "~/Projects/project/venv/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "~/Projects/project/venv/lib/python3.9/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/Cellar/[email protected]/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "~/Projects/project/appname/inventory/models/__init__.py", line 44, in <module>
    from .path import Path
  File "~/Projects/project/appname/inventory/models/path.py", line 41, in <module>
    from .step import Step
  File "~/Projects/project/appname/inventory/models/step.py", line 61, in <module>
    class Step(ModelMeta, LocalizedJSONMixin, SiteSoftDeleteModelBase, TimestampModelBase):
  File "~/Projects/project/appname/inventory/models/step.py", line 71, in Step
    slug = AutoSlugField(populate_from='name', unique=True, always_update=True, allow_unicode=True)
  File "~/Projects/project/venv/lib/python3.9/site-packages/autoslug/fields.py", line 214, in __init__
    super(SlugField, self).__init__(*args, **kwargs)
  File "~/Projects/project/venv/lib/python3.9/site-packages/django/db/models/fields/__init__.py", line 986, in __init__
    super().__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'allow_unicode'

@jared-hardy
Copy link

I would also argue for changing the default to allow_unicode=True in autoslug (despite any Django slug defaults past 1.9, conflicting or otherwise), as disallowing unicode has almost no practical benefit here, and creates needless problems with localization.

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

No branches or pull requests

3 participants