Custom site model uses the wrong manager

13 views
Skip to first unread message

briehan

unread,
Jun 28, 2011, 8:26:14 AM6/28/11
to Django users
We have a custom 'sites framework' implementation that basically
consists of a Site model and SiteManager. For some reason, when
running the app, the Site model uses the SiteManager from
django.contrib.sites instead of our own.

I did the following from within the app:

from myapp.sites.models import Site
print type(Site.objects)

<class 'django.contrib.sites.models.SiteManager'>

When doing the same from the management shell (./manage.py shell), I
get the expected output:

>>> from myapp.sites.models import Site
>>> type(Site.objects)

<class 'myapp.sites.models.SiteManager'>

The app used to run just fine on Django 1.0 and subsequently on 1.1
and 1.2 during my current upgrade attempt to get the app onto version
1.3. So, my question is: what exactly am I doing wrong or have I
stumbled upon a subtle bug of some sort?

Thanks in advance.

Briehan Lombaard

unread,
Jun 28, 2011, 9:33:24 AM6/28/11
to django...@googlegroups.com
It seems to be using the Site model (and therefore the SiteManager) from django.contrib.sites even though dhango.contrib.sites is _not_ included in my INSTALLED_APPS setting and I'm explicitly importing myapp.sites.models.Site.

bruno desthuilliers

unread,
Jun 28, 2011, 1:04:11 PM6/28/11
to Django users
On Jun 28, 2:26 pm, briehan <briehan.lomba...@gmail.com> wrote:
> We have a custom 'sites framework' implementation that basically
> consists of a Site model and SiteManager. For some reason, when
> running the app, the Site model uses the SiteManager from
> django.contrib.sites instead of our own.
>
> I did the following from within the app:
>
> from myapp.sites.models import Site
> print type(Site.objects)
>
> <class 'django.contrib.sites.models.SiteManager'>
>
> When doing the same from the management shell (./manage.py shell), I
> get the expected output:
>
> >>> from myapp.sites.models import Site
> >>> type(Site.objects)
>
> <class 'myapp.sites.models.SiteManager'>


Not enough info to be sure but looks like some sys.path order issue to
me.

bruno desthuilliers

unread,
Jun 28, 2011, 1:25:14 PM6/28/11
to Django users
On Jun 28, 7:04 pm, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:

> Not enough info to be sure but looks like some sys.path order issue to
> me.

Forgot to mention that ./manage.py and (or ?) the dev server sometimes
behave a bit strangely wrt/ imports, so depending on your code layout
and how you declare your apps in your settings.INSTALLED_APPS (ie
"myproject.myapp" or just "myapp"), you might end up with 1/ same
modules imported twice under different names (ie "sites" and
"myapp.sites") and 2/ a different sys.path than when deploying using
mod_wsgi or mod_python.

You may want to have a read at Graham Dumpleton's post about this:
http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

HTH
Reply all
Reply to author
Forward
0 new messages