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

 * status:  new => closed
 * resolution:   => needsinfo


Old description:

> In django/db/backends/util.py, in CursorDebugWrapper.execute, the line:
>
>  logger.debug('(%.3f) %s; args=%s' % (duration, sql, params),
>                 extra={'duration': duration, 'sql': sql, 'params':
> params}
>             )
>
> throws a "UnicodeDecodeError:ascii codec .... " when calling model.save()
> when some fields have utf-8/non-ascii values.  My only workaround is to
> modify it to:
>
>  logger.debug('(%.3f) %s; args=%s' % (duration, sql.decode('utf-8'),
> params),
>                 extra={'duration': duration, 'sql': sql, 'params':
> params}
>             )
>
> I'm hoping there's a better and more elegant way that I could use.
>
> Thanks!
> =)

New description:

 In django/db/backends/util.py, in CursorDebugWrapper.execute, the line:
 {{{
  logger.debug('(%.3f) %s; args=%s' % (duration, sql, params),
                 extra={'duration': duration, 'sql': sql, 'params': params}
             )
 }}}
 throws a "UnicodeDecodeError:ascii codec .... " when calling model.save()
 when some fields have utf-8/non-ascii values.  My only workaround is to
 modify it to:
 {{{
  logger.debug('(%.3f) %s; args=%s' % (duration, sql.decode('utf-8'),
 params),
                 extra={'duration': duration, 'sql': sql, 'params': params}
             )
 }}}
 I'm hoping there's a better and more elegant way that I could use.

 Thanks!
 =)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/22377#comment:15>
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.3f16ebbeef0454d57711ccb94ed238fd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to