Unicode SlugField design decision (#16501)

122 views
Skip to first unread message

Tim Graham

unread,
Nov 4, 2014, 8:27:26 PM11/4/14
to django-d...@googlegroups.com
I wanted to solicit feedback on the two approaches to supporting unicode in SlugField:

1. Added a unicode argument to models.SlugField and forms.SlugField.
https://github.com/django/django/pull/1979

2. Added models.UnicodeSlugField and forms.UnicodeSlugField.
https://github.com/django/django/pull/1987

The patch author says, "On one hand, I like the new field approach because it gives us an easier upgrade path. On the other hand, it feels like I'm polluting django.db.models and django.forms with slightly different versions of something that's already there."

Approach 1 does seem cleaner to me, but I'd be interested in hearing from those interested in this feature.

Ticket: https://code.djangoproject.com/ticket/16501

Michael Manfre

unread,
Nov 4, 2014, 10:20:58 PM11/4/14
to django-d...@googlegroups.com
Should the unicode validated field (either options) have a different internal type for the sake of 3rd party database backends? I'm not sure if any currently store SlugFIeld in an ascii char datatype and would need an easy way to differentiate.

Regards,
Michael Manfre

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/33e9747f-6ced-4710-9e59-ca128e065c5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marc Tamlyn

unread,
Nov 5, 2014, 7:16:41 AM11/5/14
to django-d...@googlegroups.com
It feels to me more like an option to SlugField and I feel UnicodeSlugField is a bit ugly. If however we find an example where Michael's point is valid (an external 3rd party backend which uses ascii chars for SlugField now) then we should go with that.

Michael Manfre

unread,
Nov 5, 2014, 10:30:09 AM11/5/14
to django-d...@googlegroups.com
We can change the internal type of SlugField for option 1 based upon whether or not the field should be unicode. Whether or not an existing backend stores SlugField in an ascii char datatype shouldn't dictate whether we go with SlugField(unicode=True) or UnicodeSlugField(). Let me rephrase the question as, Do we want to provide backends enough information so that they can decide to store an ascii slug field in an ascii char field (e.g. varchar) and a unicode slug field in a unicode char field (e.g nvarchar)?

Shai Berger

unread,
Nov 5, 2014, 7:53:53 PM11/5/14
to django-d...@googlegroups.com
On Wednesday 05 November 2014 17:29:20 Michael Manfre wrote:
> We can change the internal type of SlugField for option 1 based upon
> whether or not the field should be unicode. Whether or not an existing
> backend stores SlugField in an ascii char datatype shouldn't dictate
> whether we go with SlugField(unicode=True) or UnicodeSlugField(). Let me
> rephrase the question as, Do we want to provide backends enough information
> so that they can decide to store an ascii slug field in an ascii char field
> (e.g. varchar) and a unicode slug field in a unicode char field (e.g
> nvarchar)?
>

Could you please clarify the question? As far as I understand, schema editors
get all the information anyway.

Shai.

Michael Manfre

unread,
Nov 5, 2014, 8:18:53 PM11/5/14
to django-d...@googlegroups.com
Constructing the schema is only one part of the process. The main bit I am concerned about is how the ORM will translate the data. There are several methods on DatabaseOperatoins that exist to act based upon a field's internal type string. E.g. get_db_converters, field_cast_sql.

Marc Tamlyn

unread,
Nov 6, 2014, 2:08:20 AM11/6/14
to django-d...@googlegroups.com
Even if the backend is storing using an ascii backed data type, it should still return unicode data to Django anyway, so I'm not sure there would be a difference.

Marc

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
Reply all
Reply to author
Forward
0 new messages