#22377: SQL Logging throws an exception when fields have utf-8 characters
-------------------------------------+-------------------------------------
     Reporter:  rolanvc@…            |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.6
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:
     Keywords:  sql logging for      |  Unreviewed
  utf-8                              |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by brian):

 I can verify this occurs with Django 1.7, and only with Python2. Python3
 is fine.

 {{{
 import xyz.models as m
 m.Class.objects.filter(attribute=u'’')
 }}}

 I put the following lines in above the line where it fails
 (django/db/backends/util.py logger.debug line):

 {{{
 print type(sql)
 test = u'(%.3f) %s; args=%s' % (duration, sql, params)
 }}}

 (Yes, I know the u is redundant, wanted to make sure)

 The first line prints <type 'str'>, the second line causes the exception.

 So the problem appears to be that we are basically doing the following:

 {{{
 In [5]: u"%s" % '’'
 ---------------------------------------------------------------------------
 UnicodeDecodeError                        Traceback (most recent call
 last)
 <ipython-input-5-87d36823dac9> in <module>()
 ----> 1 u"%s" % '’'

 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0:
 ordinal not in range(128)
 }}}

 Where we should be doing this:

 {{{
 In [4]: u"%s" % u'’'
 Out[4]: u'\u2019'
 }}}

 According to ticket #18461, the result from last_executed_query should
 always be unicode, however, according to my tests, that doesn't appear to
 be happening.

--
Ticket URL: <https://code.djangoproject.com/ticket/22377#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/075.8857656d8a14f504533d95ed66cd2379%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to