jrief / django-shop

A Django based shop system
http://www.django-shop.org
BSD 3-Clause "New" or "Revised" License
32 stars 13 forks source link

AttributeError: 'mappingproxy' object has no attribute 'iteritems' #50

Closed quater closed 8 years ago

quater commented 8 years ago

As of writing this here, the Django Shop documentation http://django-shop.readthedocs.org/en/latest/tutorial/intro.html does not specify any Python version requirements. Since Django CMS supports Python 3.4 I thought that I can use Python 3.4 for Django Shop as well.

However it appears that parts of Django Shop are not yet compatible with Python 3.x.

While dealing with issue https://github.com/jrief/django-shop/issues/48 I was using Python 3.4 and encountered the below error:

(shoptutorial) vagrant@vagrant:~/django-shop/example$ ./manage.py migrate
/home/vagrant/django-shop/shop/models/order.py:95: RemovedInDjango19Warning: import_by_path() has been deprecated. Use import_string() instead.
  bases = tuple(import_by_path(mc) for mc in shop_settings.ORDER_WORKFLOWS) + bases

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/core/management/__init__.py", line 328, in execute
    django.setup()
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/vagrant/shoptutorial/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/vagrant/django-shop/example/myshop/models/__init__.py", line 9, in <module>
    from shop.models.defaults.order import Order
  File "/home/vagrant/django-shop/shop/models/defaults/order.py", line 9, in <module>
    class Order(order.BaseOrder):
  File "/home/vagrant/django-shop/shop/models/order.py", line 105, in __new__
    attrs['_auto_transitions'].update(cls.add_to_auto_transitions(b))
  File "/home/vagrant/django-shop/shop/models/order.py", line 112, in add_to_auto_transitions
    for name, method in base.__dict__.iteritems():
AttributeError: 'mappingproxy' object has no attribute 'iteritems'

As of the Python documentation this error is due to iteritems having been deprecated with the introduction of Python 3.x.

https://wiki.python.org/moin/Python3.0

Remove dict.iteritems(), dict.iterkeys(), and dict.itervalues(). Instead: use dict.items(), dict.keys(), and dict.values() respectively.

This problem is not observed while Python 2.7.6 is used.

jrief commented 8 years ago

Thanks for reporting. The syntax has been adopted to be Python 3 compatible.

quater commented 8 years ago

Thanks for the quick turnaround. Based on your feedback I went on to checkout your latest commit https://github.com/jrief/django-shop/commit/08454d1a5fa861800d8656a8d242c097ac222c1e.

While running manage.py migrate I still encountered an error, indicating that there is at least one more place (i.e. django-shop/shop/apps.py), where the code would need to be re-factored.

(shoptutorial) vagrant@vagrant:~/django-shop/example$ ./manage.py migrate
/home/vagrant/shoptutorial/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
  return f(*args, **kwds)

/home/vagrant/shoptutorial/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: The django.forms.util module has been renamed. Use django.forms.utils instead.
  return f(*args, **kwds)

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/core/management/__init__.py", line 328, in execute
    django.setup()
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/home/vagrant/django-shop/shop/apps.py", line 22, in ready
    if get_version() < (1, 8):
TypeError: unorderable types: str() < tuple()
jrief commented 8 years ago

should be fixed now

quater commented 8 years ago

That moved us to the next error...

(shoptutorial) vagrant@vagrant:~/django-shop/example$ ./manage.py migrate
/home/vagrant/shoptutorial/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
  return f(*args, **kwds)

/home/vagrant/shoptutorial/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: The django.forms.util module has been renamed. Use django.forms.utils instead.
  return f(*args, **kwds)

Traceback (most recent call last):
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/db/models/fields/related.py", line 2138, in __init__
    to._meta
AttributeError: 'bytes' object has no attribute '_meta'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 93, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/db/migrations/loader.py", line 185, in build_graph
    self.load_disk()
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/db/migrations/loader.py", line 103, in load_disk
    migration_module = import_module("%s.%s" % (module_name, migration_name))
  File "/home/vagrant/shoptutorial/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/vagrant/django-shop/email_auth/migrations/0001_initial.py", line 11, in <module>
    class Migration(migrations.Migration):
  File "/home/vagrant/django-shop/email_auth/migrations/0001_initial.py", line 32, in Migration
    ('groups', models.ManyToManyField(related_query_name='user', related_name='user_set', to=b'auth.Group', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of his/her group.', verbose_name='groups')),
  File "/home/vagrant/shoptutorial/lib/python3.4/site-packages/django/db/models/fields/related.py", line 2143, in __init__
    (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
AssertionError: ManyToManyField(b'auth.Group') is invalid. First parameter to ManyToManyField must be either a model, a model name, or the string 'self'
jrief commented 8 years ago

This error was also discovered by our unit tests, check here: https://travis-ci.org/jrief/django-shop/jobs/106527945 we still allow to fail for Py-3

for the moment, it probably is better to proceed with Python-2.7.10. This is the version used for development.

jrief commented 8 years ago

the last error is weird. Its ./manage.py makemigrations which produced that code. You you please try to create the migration files using Py-3.4 and apply them yourself.

rfleschenberg commented 8 years ago

This issue was moved to awesto/django-shop#316