Hi all,

Not sure if this is actually a bug (or has already been spotted but couldn't
see a trac ticket for it). It seems MySQL has some peculiarities in the way
it treats trailing spaces in character
columns<http://dev.mysql.com/doc/refman/5.1/en/char.html>:
they will be ignored for comparison purposes so the following test case
passes on MySQL:
class ShowBug(models.Model):
    """
    >>> from testcase.models import  ShowBug
    >>> sb = ShowBug(name='this has a trailing space ', shoe_size=41)
    >>> sb.save()
    >>> ShowBug.objects.filter(name__exact='this has a trailing space')
    [<ShowBug: [this has a trailing space ]>]

    >>> ShowBug.objects.filter(name__exact='THIS has a trailing space')
    [<ShowBug: [this has a trailing space ]>]

    >>> ShowBug.objects.filter(name__exact='this has a trailing space ')
    [<ShowBug: [this has a trailing space ]>]

    >>> ShowBug.objects.filter(name__exact='THIS has a trailing space ')
    [<ShowBug: [this has a trailing space ]>]

    >>> ShowBug.objects.filter(name__iexact='this has a trailing space')
    []

    >>> ShowBug.objects.filter(name__iexact='THIS has a trailing space')
    []

    """
    name = models.CharField(max_length=100)
    shoe_size = models.IntegerField()

    def __unicode__(self):
        return '[%s]' % (self.name,)

But won't pass on SQLite, for instance.

I understand that the *exact* operator is relying on the (case insensitive
by default) MySQL DB collation and I'm happy with this. It also seems to be
relying on the DB's comparison engine (which IMHO appears broken in
MySQL). I would say the behaviour of *iexact* certainly looks inconsistent
as it is *more* exact than *exact* but on balance it appears that *exact* is
not doing the right thing here?

I'm using Django 1.2.1 and MySQL 5.1.47 on Mac OS X Leopard (but originally
spotted on Fedora 12 with MySQL 5.1.44, I think).

It has been a pleasure working with Django these last 5 months or so! I can
post code to a trac ticket if that could be useful.
Steven.

P.S. Happy to try and help fix if it needs that, but might need some help
getting started.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to