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

Fix str != unicode issue, if source was type str (Model.objects.create) #9

Merged
merged 1 commit into from Sep 17, 2015

Conversation

cyberstar
Copy link
Contributor

If someone will create object using manager and will provide string values for fields we get an exception (events example):

Traceback (most recent call last):
  File "./aldryn_events/tests/test_utils.py", line 19, in test_build_calendar
    publish_at=tz_datetime(2015, 2, 10)
  File "./aldryn_events/tests/base.py", line 110, in create_event
    event = Event.objects.create(**en)
  File "/Users/Starky/projects/aldryn/aldryn-events/.tox/py27-dj17-cms31/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/Starky/projects/aldryn/aldryn-events/.tox/py27-dj17-cms31/lib/python2.7/site-packages/aldryn_apphooks_config/managers/parler.py", line 30, in create
    return super(TranslatableQuerySet, self).create(**kwargs)
  File "/Users/Starky/projects/aldryn/aldryn-events/.tox/py27-dj17-cms31/lib/python2.7/site-packages/django/db/models/query.py", line 372, in create
    obj.save(force_insert=True, using=self.db)
  File "/Users/Starky/projects/aldryn/aldryn-events/.tox/py27-dj17-cms31/lib/python2.7/site-packages/aldryn_translation_tools/models.py", line 123, in save
    ideal_slug = force_text(slugify(source))
  File "/Users/Starky/projects/aldryn/aldryn-events/.tox/py27-dj17-cms31/lib/python2.7/site-packages/django/utils/functional.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "/Users/Starky/projects/aldryn/aldryn-events/.tox/py27-dj17-cms31/lib/python2.7/site-packages/django/utils/text.py", line 442, in slugify
    value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
TypeError: must be unicode, not str

So ensure that source value has the correct type before passing it to slugify

@intellectronica
Copy link

👍

cyberstar pushed a commit to aldryn/aldryn-events that referenced this pull request Sep 17, 2015
…new release

Though i think it is a great idea to move everything to unicode literlas the main issue is described here:
divio/aldryn-translation-tools#9
@mkoistinen
Copy link
Contributor

LGTM

cyberstar pushed a commit that referenced this pull request Sep 17, 2015
…-is-unicode

Fix str != unicode issue, if source was type str (Model.objects.create)
@cyberstar cyberstar merged commit 67a59b6 into master Sep 17, 2015
@cyberstar cyberstar deleted the issue/slug-generation-ensure-source-is-unicode branch September 17, 2015 13:27
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

Successfully merging this pull request may close these issues.

None yet

3 participants