Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django 1.9: cannot import name 'Constraint' #349

Closed
bibenga opened this issue Dec 2, 2015 · 19 comments
Closed

django 1.9: cannot import name 'Constraint' #349

bibenga opened this issue Dec 2, 2015 · 19 comments

Comments

@bibenga
Copy link

bibenga commented Dec 2, 2015

after migrate to Django 1.9 (on python 3.4.3)

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fec2f2e1268>
Traceback (most recent call last):
  File "/opt/py3-venev/lib/python3.4/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/opt/py3-venev/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/opt/py3-venev/lib/python3.4/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/opt/py3-venev/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/opt/py3-venev/lib/python3.4/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/opt/py3-venev/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/opt/py3-venev/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/opt/py3-venev/lib/python3.4/site-packages/modeltranslation/apps.py", line 11, in ready
    handle_translation_registrations()
  File "/opt/py3-venev/lib/python3.4/site-packages/modeltranslation/models.py", line 81, in handle_translation_registrations
    autodiscover()
  File "/opt/py3-venev/lib/python3.4/site-packages/modeltranslation/models.py", line 16, in autodiscover
    from modeltranslation.translator import translator
  File "/opt/pye-venevlib/python3.4/site-packages/modeltranslation/translator.py", line 12, in <module>
    from modeltranslation.manager import (MultilingualManager, MultilingualQuerysetManager,
  File "/opt/py3-venev/lib/python3.4/site-packages/modeltranslation/manager.py", line 19, in <module>
    from django.db.models.sql.where import Constraint
ImportError: cannot import name 'Constraint'
@kamikaze
Copy link

kamikaze commented Dec 2, 2015

+1

@zlorf
Copy link
Collaborator

zlorf commented Dec 2, 2015

Argh, Django 1.9 support wasn't implemented yet. It seems we need to add it quickly.

@simons-design
Copy link

+1

3 similar comments
@illing2005
Copy link

+1

@liminspace
Copy link

+1

@SunFulong
Copy link

+1

@BluntlyCat
Copy link

+1

For a quick solution:

  1. Disable modeltranslation in settings.py (installed apps)
  2. Change your affected admin.py files as follows:
try:
    # If everithing is fine we simply can go ahead...
    from modeltranslation.admin import TranslationAdmin
    ADMIN_MODEL = TranslationAdmin
except ImportError:
    # Catch the import exception if it does not work for some reason and fallback to default
    ADMIN_MODEL = admin.ModelAdmin
...
class PersonAdmin(ADMIN_MODEL):

Then your pages should load for now - of course without translations - but work.
If support for django 1.9 will be implemented soon, you just have to enable modeltranslation without the need to change the other files.

@SalahAdDin
Copy link

👍

1 similar comment
@juanwolf
Copy link

juanwolf commented Dec 6, 2015

👍

@zlorf
Copy link
Collaborator

zlorf commented Dec 6, 2015

Trying to fix it today. It seems, however, that many internal APIs have changed.

zlorf added a commit that referenced this issue Dec 6, 2015
@zlorf
Copy link
Collaborator

zlorf commented Dec 6, 2015

I've managed to get tests passing with Django 1.9.
But it will be nice if you can verify if everything works as expected by testing your apps against https://github.com/deschler/django-modeltranslation/archive/master.zip .

@stwa
Copy link

stwa commented Dec 6, 2015

I did a quick test, the import Constraint error is gone, I now have problems when running ./manage.py makemigrations:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/stw/.venvs/xyz.com/lib/python3.4/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/home/stw/.venvs/xyz.com/lib/python3.4/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/stw/.venvs/xyz.com/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/stw/.venvs/xyz.com/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/stw/.venvs/xyz.com/lib/python3.4/site-packages/django/core/management/commands/makemigrations.py", line 106, in handle
    ProjectState.from_apps(apps),
  File "/home/stw/.venvs/xyz.com/lib/python3.4/site-packages/django/db/migrations/state.py", line 174, in from_apps
    model_state = ModelState.from_model(model)
  File "/home/stw/.venvs/xyz.com/lib/python3.4/site-packages/django/db/migrations/state.py", line 398, in from_model
    e,
TypeError: Couldn't reconstruct field name_de on common.Insignia: __init__() missing 3 required positional arguments: 'translated_field', 'language', and 'empty_value'

@zlorf
Copy link
Collaborator

zlorf commented Dec 6, 2015

@stwa There was indeed some problem with migrations. It should be gone now.

@stwa
Copy link

stwa commented Dec 6, 2015

Works for me now... Thanks for your great work!

@BluntlyCat
Copy link

For me it works too, thank you much for the very quick fix!!!

@zlorf
Copy link
Collaborator

zlorf commented Dec 7, 2015

@deschler, can we make a RC release for people to test? Or do you prefer to release a "stable" version?

@deschler
Copy link
Owner

deschler commented Dec 7, 2015

Great job! RC makes sense, there are some bigger changes. I will prepare a release today.
By the way, i think we can drop support for some older Django (and Python) versions for 0.11.

@zlorf
Copy link
Collaborator

zlorf commented Dec 7, 2015

Well, it seems it's still working with older Djangos and Pythons, so maybe let's don't drop this compatibility yet if it is "free" now
(and make major code cleanup for 0.12).

@deschler
Copy link
Owner

deschler commented Dec 7, 2015

Sounds like a plan. :)
0.11rc1 is released.

@deschler deschler closed this as completed Dec 7, 2015
decentral1se added a commit to aptivate/django-multilingual-search that referenced this issue Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests