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

Problem with Apache and mod_wsgi #15

Closed
nknj opened this issue Nov 29, 2012 · 10 comments
Closed

Problem with Apache and mod_wsgi #15

nknj opened this issue Nov 29, 2012 · 10 comments

Comments

@nknj
Copy link

nknj commented Nov 29, 2012

I just experienced the same problem as http://django-irc-logs.com/2012/sep/30/#747079

This happens only on apache with mod_wsgi. Every second or third time I refresh the page, I get a 500 error: from django.contrib.admin import ModelAdmin, actions; ImportError: cannot import name actions;

This problem disappears when I remove longerusername from my installed apps.

@skoczen
Copy link
Owner

skoczen commented Nov 29, 2012

This line:
django.contrib.admin import ModelAdmin, actions;

Doesn't appear anywhere within longerusername. The only guess I've got is that apache's mod_wsgi is doing some weird caching of pycs and doesn't accept the monkeypatch.

Given that this isn't on fire for anyone else, I'd honestly say your best bets to get this fixed are:

  • switch to a better way to server your django app (gunicorn, etc - most serious django folks I know haven't touched apached for years), or
  • dig in, get the monkeypatch working, and send in a pull request.

Apologies for not having a better answer, but I've found it's better to be honest with folks about how much time I've got to split between open source projects, and their best avenues for a fix.

Best of luck, and feel free to throw comments on here as you debug / find a solution!

@nknj
Copy link
Author

nknj commented Nov 30, 2012

Thanks skoczen. I am pretty new to all this but if i manage to find a fix I will send in a pull request.

@joaolsilva
Copy link

I had a similar problem, and commenting the field.help_text line in models.py fixed it.

@neilp9
Copy link

neilp9 commented May 4, 2013

@joaolsilva I experienced the same problem and fixed it with what you suggested. @skoczen any idea about why this is happening and how to fix it?

@skoczen
Copy link
Owner

skoczen commented May 4, 2013

@neilp9 sorry, nope. Everything I know is in the comment above. If you've got a fix though, send a pull!

@neilp9
Copy link

neilp9 commented May 5, 2013

OK @skoczen. Just for reference, here's my stack trace:

File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 143, in filter
return self.get_query_set().filter(_args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 624, in filter
return self._filter_or_exclude(False, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 642, in _filter_or_exclude
clone.query.add_q(Q(_args, *_kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1250, in add_q
can_reuse=used_aliases, force_having=force_having)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1122, in add_filter
process_extras=process_extras)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1304, in setup_joins
field, model, direct, m2m = opts.get_field_by_name(name)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 311, in get_field_by_name
cache = self.init_name_map()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 341, in init_name_map
for f, model in self.get_all_related_m2m_objects_with_model():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 429, in get_all_related_m2m_objects_with_model
cache = self._fill_related_many_to_many_cache()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 443, in _fill_related_many_to_many_cache
for klass in get_models(only_installed=False):
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 181, in get_models
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 86, in load_app
app_module = import_module(app_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
import(name)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/init.py", line 6, in
from django.contrib.admin.sites import AdminSite, site
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py", line 3, in
from django.contrib.admin import ModelAdmin, actions
ImportError: cannot import name actions

@mpcabd
Copy link

mpcabd commented Aug 10, 2013

Got the same error and fixed by commenting the help text line.

@radzhome
Copy link

radzhome commented Aug 6, 2014

Just to confirm, same issue on gunicorn 18 and 19 and nginx, using django_gunicorn deployment which is deprecated. I will be switching to wsgi and see if the problem persists, but yes commeting out help_text does do the trick. I found this to be somewhat informative on the issue, and it does note that its a deployment issue: http://askbot.org/en/question/9594/why-askbot-works-with-runserver-but-fails-with-production-server/

@radzhome
Copy link

radzhome commented Aug 6, 2014

To further confirm, I still run into this issue using gunicorn but only if I run it as a service from /etc/init/service.conf , from the command line it runs fine.

By using lazy ugetttext (from django.utils.translation import ugettext_lazy as _) instead in models.py seems to fix the problem.

Its odd that it runs under certain deployment routes and not others. (runserver OK, gunicorn in command line OK, gunicorn as a service FAIL)

@skoczen
Copy link
Owner

skoczen commented May 29, 2015

Closing this up, since the supported solution is to use the more maintained fork https://github.com/madssj/django-longer-username-and-email, or Django 1.5+'s custom user models.

Thanks!
-Steven

@skoczen skoczen closed this as completed May 29, 2015
ErwinJunge added a commit to ErwinJunge/django-longer-username-and-email that referenced this issue Jul 15, 2015
madssj added a commit to madssj/django-longer-username-and-email that referenced this issue Jul 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants