ImportError: cannot import name actions

714 views
Skip to first unread message

rok

unread,
Oct 15, 2013, 5:08:35 PM10/15/13
to django...@googlegroups.com
I have recently been testing the 1.6b4 tag with a new app we are writing, using apache and wsgi. However, I could not get rid of the following issue happening on every request:

...
[Tue Oct 15 12:50:36 2013] [error] [client 127.0.0.1]   File "/home/rok/apps/django-trunk/django/contrib/gis/admin/__init__.py", line 2, in <module>
[Tue Oct 15 12:50:36 2013] [error] [client 127.0.0.1]     from django.contrib.admin import autodiscover, site, AdminSite, ModelAdmin, StackedInline, TabularInline, HORIZONTAL, VERTICAL
[Tue Oct 15 12:50:36 2013] [error] [client 127.0.0.1]   File "/home/rok/apps/django-trunk/django/contrib/admin/__init__.py", line 6, in <module>
[Tue Oct 15 12:50:36 2013] [error] [client 127.0.0.1]     from django.contrib.admin.sites import AdminSite, site
[Tue Oct 15 12:50:36 2013] [error] [client 127.0.0.1]   File "/home/rok/apps/django-trunk/django/contrib/admin/sites.py", line 3, in <module>
[Tue Oct 15 12:50:36 2013] [error] [client 127.0.0.1]     from django.contrib.admin import ModelAdmin, actions
[Tue Oct 15 12:50:36 2013] [error] [client 127.0.0.1] ImportError: cannot import name actions

by doing the following change, I could get rid of what looked like a circular import issue:
--- a/django/contrib/admin/sites.py
+++ b/django/contrib/admin/sites.py
@@ -1,6 +1,7 @@
 from functools import update_wrapper
 from django.http import Http404, HttpResponseRedirect
-from django.contrib.admin import ModelAdmin, actions
+from django.contrib.admin import ModelAdmin
+from django.contrib.admin.actions import delete_selected
 from django.contrib.admin.forms import AdminAuthenticationForm
 from django.contrib.auth import REDIRECT_FIELD_NAME
 from django.contrib.contenttypes import views as contenttype_views
@@ -46,7 +47,7 @@ class AdminSite(object):
         self._registry = {}  # model_class class -> admin_class instance
         self.name = name
         self.app_name = app_name
-        self._actions = {'delete_selected': actions.delete_selected}
+        self._actions = {'delete_selected': delete_selected}
         self._global_actions = self._actions.copy()
 
     def register(self, model_or_iterable, admin_class=None, **options):

Switching to 1.5.4 resolves the issue as well (even though the sites.py code is the same). What is more, this did not occur in the development environment when using the runserver run.

Any clue?

the.pa...@gmail.com

unread,
Oct 16, 2013, 7:39:28 AM10/16/13
to django...@googlegroups.com
Hi!

-------- Original Message --------
Subject: Re: ImportError: cannot import name actions
Date: Wed, 16 Oct 2013 11:26:33 +0400
From: Ivan Kharlamov <the.pa...@gmail.com>
To: django-d...@googlegroups.com
Well, if this doesn't happen in the dev environment and does happen in
production, is there any chance that you're using gunicorn via
`gunicorn_django` command? If yes, try running the project with
`gunicorn` command instead.

I have seen some weird import errors which occured only when I was
running the project with `gunicorn_django` in conjunction with Django
1.6, but I didn't take time to debug and report them since
`gunicorn_django` command is deprecated and switching to `gunicorn`
command fixed everything.

Still, I have written about them on SO: http://stackoverflow.com/questions/16369354/why-is-gunicorn-django-not-recommended-anymore/16373778#16373778

Hope this helps!

Regards,
Ivan

rok

unread,
Oct 16, 2013, 12:18:13 PM10/16/13
to django...@googlegroups.com
Hi Ivan, thanks for the response. No. we are not using gunicorn, just  apache+mod_wsgi.

moreover, I configured WSGIDaemon option for the host to separate it from the rest of the system and still no luck.

Rok

the.pa...@gmail.com

unread,
Oct 16, 2013, 2:20:12 PM10/16/13
to django...@googlegroups.com


Ouch! I should have read your post more carefully! If you don't have any other options than to use Apache, you could run it as proxy to gunicorn. Or you could use Nginx instead of Apache...
 

Tom Evans

unread,
Oct 16, 2013, 3:17:35 PM10/16/13
to django...@googlegroups.com
On Wed, Oct 16, 2013 at 3:20 PM, <the.pa...@gmail.com> wrote:
> Ouch! I should have read your post more carefully! If you don't have any
> other options than to use Apache, you could run it as proxy to gunicorn. Or
> you could use Nginx instead of Apache...

What, precisely, is wrong with Apache httpd/mod_wsgi as a hosting solution?

httpd can be as lean and efficient as nginx in memory usage if you
configure it so, doesn't abandon the httpd ecosystem, and can actually
host wsgi apps itself, rather than requiring yet another webserver in
to the mix.

Especially so, I'd imagine, if that other webserver has, in your words
"some weird import errors which occured only when I was running the
project with `gunicorn_django"

Cheers

Tom

rok

unread,
Oct 16, 2013, 3:23:53 PM10/16/13
to django...@googlegroups.com, teva...@googlemail.com
Hi, I am not a particular evangelist of one or the other but since we use apache+mod_wsgi for several apps throughout the company, we obviously want to stick with one, easier for deployment and maintenance. 

the.pa...@gmail.com

unread,
Oct 17, 2013, 5:44:15 AM10/17/13
to django...@googlegroups.com
Hi, Tom and rok!

I didn't mean to start http server flame war, Apache obviously has it's upsides and we also use it. What I've proposed is a simple, albeit dirty, workaround to run non-forked Django 1.6 in production.

For Django devs to be able to address the root of the issue and solve it properly you will probably need to prepare a sample bare bones Django project that has the issue.

y venkatesh

unread,
Oct 17, 2013, 11:33:13 AM10/17/13
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages