Bug #72001 django connector: iteritems() not supported in python 3
Submitted: 10 Mar 2014 21:33 Modified: 28 Mar 2014 17:14
Reporter: Nicolás Aimetti Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S1 (Critical)
Version:1.1.6 OS:Any
Assigned to: CPU Architecture:Any
Tags: Django

[10 Mar 2014 21:33] Nicolás Aimetti
Description:
Trying to run syncdb with a fixture in django 1.6, with python 3.2:

./manage.py syncdb 
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib64/python3.2/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/lib64/python3.2/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib64/python3.2/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib64/python3.2/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/lib64/python3.2/site-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/usr/lib64/python3.2/site-packages/django/core/management/commands/syncdb.py", line 162, in handle_noargs
    database=db, skip_validation=True)
  File "/usr/lib64/python3.2/site-packages/django/core/management/__init__.py", line 159, in call_command
    return klass.execute(*args, **defaults)
  File "/usr/lib64/python3.2/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/lib64/python3.2/site-packages/django/core/management/commands/loaddata.py", line 55, in handle
    self.loaddata(fixture_labels)
  File "/usr/lib64/python3.2/site-packages/django/core/management/commands/loaddata.py", line 90, in loaddata
    connection.check_constraints(table_names=table_names)
  File "/usr/lib64/python3.2/site-packages/mysql/connector/django/base.py", line 617, in check_constraints
    self.introspection.get_primary_key_column(cursor, table_name)
  File "/usr/lib64/python3.2/site-packages/mysql/connector/django/introspection.py", line 146, in get_primary_key_column
    for column in self.get_indexes(cursor, table_name).iteritems():
AttributeError: Problem installing fixtures: 'dict' object has no attribute 'iteritems'

The error is pretty simple: iteritems function was removed from python 3.*

How to repeat:
Try to syncdb in django with a fixture of some simple models, or just call make some unit testing on instrospection.get_primary_key_column

Suggested fix:
I've just commented in ysql/connector/django/introspection.py the las function "get_primary_key_column" (in django introspection.py module there isn't such function) and everything works fine, but I don't think that as was o good solution.
[11 Mar 2014 3:30] Nicolás Aimetti
Other posibles solutions: 

*use utems in place of iteritems 

# Django 1.6
for key,val in self.get_indexes(cursor, table_name).items():
     if val['primary_key']:
         return key
     return None

* use django.utils.six.iteritems
[28 Mar 2014 17:14] Paul DuBois
Noted in 1.1.7 changelog.

For Django, introspecting to get the primary key of MySQL tables
could fail in Python 3.