Opened 5 years ago

Closed 4 years ago

#13322 closed Bug (needsinfo)

Problem with inspectdb and encoding

Reported by: josemaria@… Owned by: nobody
Component: Core (Management commands) Version: 1.2-beta
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX:

Description (last modified by Alex)

While trying to generate model from database with manage.py inspectdb I get the following error:

class Categorias(models.Model):
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 223, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 352, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/commands/inspectdb.py", line 22, in handle_noargs
    for line in self.handle_inspection(options):
  File "/usr/local/lib/python2.6/site-packages/django/core/management/commands/inspectdb.py", line 113, in handle_inspection
    field_desc = '%s = models.%s' % (att_name, field_type)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)

Attachments (1)

13322-test.diff (527 bytes) - added by claudep 4 years ago.
Tentative test (worksforme)

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by josemaria@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

While trying to generate model from database with manage.py inspectdb I get the following error:

class Categorias(models.Model):
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 223, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 352, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/commands/inspectdb.py", line 22, in handle_noargs
    for line in self.handle_inspection(options):
  File "/usr/local/lib/python2.6/site-packages/django/core/management/commands/inspectdb.py", line 113, in handle_inspection
    field_desc = '%s = models.%s' % (att_name, field_type)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)

comment:2 Changed 5 years ago by Alex

  • Description modified (diff)

Please use preview.

comment:3 Changed 5 years ago by josemaria@…

  • Component changed from Uncategorized to django-admin.py inspectdb
  • Has patch set
  • milestone set to 1.2

Decode UTF-8 for table attribute names:

--- django/core/management/commands/inspectdb.py        (revisión: 12947)
+++ django/core/management/commands/inspectdb.py        (copia de trabajo)
@@ -110,7 +110,7 @@
                     if not field_type in ('TextField(', 'CharField('):
                         extra_params['null'] = True

-                field_desc = '%s = models.%s' % (att_name, field_type)
+                field_desc = '%s = models.%s' % (att_name.decode('utf-8'), field_type)
                 if extra_params:
                     if not field_desc.endswith('('):
                         field_desc += ', '

comment:4 Changed 5 years ago by russellm

  • milestone 1.2 deleted
  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

This isn't critical for 1.2.

It's difficult to evaluate whether the patch is correct without seeing a test case.

comment:5 Changed 5 years ago by josemaria@…

Test case:

create table test (
   día date
);

----------------------------

myconsole> django-admin.py inspectdb

----------------------------


comment:6 Changed 4 years ago by gabrielhurley

  • Component changed from django-admin.py inspectdb to Core (Management commands)

comment:7 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

Changed 4 years ago by claudep

Tentative test (worksforme)

comment:8 Changed 4 years ago by claudep

  • Easy pickings unset
  • Resolution set to needsinfo
  • Status changed from new to closed

I attached a test that works for me (SQLite/Python2.6/Linux). But the problem might be triggered by a specific backend/python/OS combination. You should give more information about the conditions under which you are able to reproduce the bug.

Note: See TracTickets for help on using tickets.
Back to Top