You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem occurs when I try to save Query model with unsluggable data in the text field:
>>> Query.objects.get_or_create(text="???????")
***\lib\site-packages\autoslug\fields.py in pre_save(self, instance, add)
270
271 if not self.blank:
--> 272 assert slug, 'slug is defined before trying to ensure uniqueness'
273
274 if slug:
AssertionError: slug is defined before trying to ensure uniqueness
The source of the problem is following code in autoslug/utils.py (Note: I have unidecode installed):
# ...# Use Django's default method over decoded stringdefslugify(value):
returndjango_slugify(unidecode(value))
# ...
Django slugify function fails to create slug from text ??????? and autoslug fails on AssertionError.
I don't know how should autoslug behave in these situations but it would be great to provide nicer error (e.g. raise ValueError("Sorry but it is not possible to create slug from...")).
To @egregors: Try to install unidecode: pip install unidecode. Standard slugify function in Django doesn't work on all non-ascii data:
In [1]: fromdjango.template.defaultfiltersimportslugifyIn [2]: slugify('Привет!')
Out[2]: ''
vs:
In [4]: fromunidecodeimportunidecodeIn [5]: unidecode('Привет!')
Out[5]: 'Privet!'
I have the exact same issue as described on Bitbucket: https://bitbucket.org/neithere/django-autoslug/issues/45/slug-is-defined-before-trying-to-ensure.
Here is my code (Django
1.10.3
and Python3.5.2
):The problem occurs when I try to save
Query
model with unsluggable data in thetext
field:The source of the problem is following code in
autoslug/utils.py
(Note: I haveunidecode
installed):Django
slugify
function fails to create slug from text???????
and autoslug fails onAssertionError
.I don't know how should autoslug behave in these situations but it would be great to provide nicer error (e.g. raise
ValueError("Sorry but it is not possible to create slug from...")
).To @egregors: Try to install unidecode:
pip install unidecode
. Standardslugify
function in Django doesn't work on all non-ascii data:vs:
Autoslug will use
unidecode
automatically, see this code: https://github.com/neithere/django-autoslug/blob/master/autoslug/utils.py#L19-L20.The text was updated successfully, but these errors were encountered: