#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 | -------------------------------------+------------------------------------- Changes (by kahnert):
* status: closed => new * resolution: needsinfo => Comment: Here is a traceback: {{{ Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/mnt/schedenv/local/lib/python2.7/site- packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/mnt/schedenv/local/lib/python2.7/site- packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/mnt/schedenv/local/lib/python2.7/site- packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/mnt/schedenv/local/lib/python2.7/site- packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/home/kahnert/pycharm/schedules/schedules/data/management/commands/import_data.py", line 35, in handle self.parse_file(fname) File "/home/kahnert/pycharm/schedules/schedules/data/management/commands/import_data.py", line 40, in parse_file self.parse_entry(cols) File "/home/kahnert/pycharm/schedules/schedules/data/management/commands/import_data.py", line 61, in parse_entry row_header, created = OIRowHeader.objects.get_or_create(**header_vals) File "/mnt/schedenv/local/lib/python2.7/site- packages/django/db/models/manager.py", line 154, in get_or_create return self.get_queryset().get_or_create(**kwargs) File "/mnt/schedenv/local/lib/python2.7/site- packages/django/db/models/query.py", line 376, in get_or_create return self.get(**lookup), False File "/mnt/schedenv/local/lib/python2.7/site- packages/django/db/models/query.py", line 304, in get num = len(clone) File "/mnt/schedenv/local/lib/python2.7/site- packages/django/db/models/query.py", line 77, in __len__ self._fetch_all() File "/mnt/schedenv/local/lib/python2.7/site- packages/django/db/models/query.py", line 857, in _fetch_all self._result_cache = list(self.iterator()) File "/mnt/schedenv/local/lib/python2.7/site- packages/django/db/models/query.py", line 220, in iterator for row in compiler.results_iter(): File "/mnt/schedenv/local/lib/python2.7/site- packages/django/db/models/sql/compiler.py", line 713, in results_iter for rows in self.execute_sql(MULTI): File "/mnt/schedenv/local/lib/python2.7/site- packages/django/db/models/sql/compiler.py", line 786, in execute_sql cursor.execute(sql, params) File "/mnt/schedenv/local/lib/python2.7/site- packages/django/db/backends/util.py", line 78, in execute logger.debug('(%.3f) %s; args=%s' % (duration, sql, params), UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 450: ordinal not in range(128) }}} I can't provide the data values, most likely some russian or chinese string, but I think the bug is obvious if you look into `django.db.backends.util.CursorDebugWrapper`: - Python 2 - percent-formatting into bytestrings (`str`-Type) -> UnicodeDecodeError for any non-ascii char The solution should be as simple as: Use `six` string types This is realy a hassle, since you have to work around '''de'''bugging Code at the moment. -- Ticket URL: <https://code.djangoproject.com/ticket/22377#comment:3> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/075.69b396fd87bf0f131a4474609d45ad8d%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.