wemake-services/django-split-settings

Error with unicode module names on Python2

brutus opened this issue · 5 comments

I maintain a Django installation and want to migrate the settings (lots of from X import *) to django-split-setings. Seems everything went fine, but the tox test for Python 2.7 (the only tested version < 3) bailed on me with the following error:

Traceback (most recent call last):
  File ".tox/py27/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 302, in execute
    settings.INSTALLED_APPS
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
    self._setup(name)
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/…/source/streambox/streambox/settings/test.py", line 19, in <module>
    scope=globals()
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/split_settings/tools.py", line 84, in include
    exec(compile(to_compile.read(), included_file, 'exec'), scope)
  File "/home/…/source/streambox/streambox/settings/components/base.py", line 147, in <module>
    scope=globals()
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/split_settings/tools.py", line 90, in include
    module = types.ModuleType(module_name)
TypeError: module.__init__() argument 1 must be string, not unicode

This might be a result of from __future__ import unicode_literals. Any ideas how to handle this?

Thanks, will dig it soon. Do you have any fix for yourself?

Not really… For starters we just dropped Python 2 support (cause it's not needed in house). But that's temporary, cause we would like to keep 2.7 supported. I'm not sure, if unicode_literals is absolutely needed, but have to read up on it and check our code a lot more.

So, just workarounds for now. I was thinking about monkey–patching and "byteify" the relevant parts… but not sure where to start and what's relevant.

Thanks for the fast fix!

While we will wait with re–enabling Python 2 support for your next release, I ran the latest Github version in some test environments and it works.

Nice, I will release it soon.