Changes between Initial Version and Version 1 of Ticket #16368, comment 15


Ignore:
Timestamp:
07/27/2011 07:13:55 PM (4 years ago)
Author:
lakin
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #16368, comment 15

    initial v1  
    11I'm re-opening this as I feel that I can better explain what is happening here.  It is the combination of a few different, but important aspects and there may be a few different fixes that are in order.
    22
    3 First off - from the sites documentation - https://docs.djangoproject.com/en/dev/ref/contrib/sites/#requestsite-objects  There are parts of django that use the sites framework even if it's not installed.  So ultimately, there valid use cases where the sites app is NOT installed, but it IS imported.  This is an important distinction.  In these case, I feel that it is reasonable that one should be able to make a new sites app with a model called Site.
     3First off - from the sites documentation - https://docs.djangoproject.com/en/dev/ref/contrib/sites/#requestsite-objects  There are parts of django that use the sites framework even if it's not installed.  So ultimately, there valid use cases where the sites app is NOT installed, but it IS imported.  This is an important distinction.  In these cases, I feel that it is reasonable that one should be able to make a new sites app with a model called Site.
    44
    55The above is not a bug, in and of itself.  However, when the sites app is imported, its models.py is also imported.  When the models.py is imported the ModelBase metaclass runs and prepares this model.  It also caches this model for future use so that subsequent imports don't go through the costly process of preparing the model a second time.  However, it caches the model based on the app_label and model class name, which in this case is 'sites.Site'.  When the new, custom app is imported, the same process occurs. However - this time around it notices that it already prepared a 'sites.Site' - so rather than making a new one, it returns a reference to the old one.  However, in this particular case it will always the wrong reference.  It will always be a reference to the non-used django.contrib.sites.models.Site model instead of the custom one.  For reference, this is the code that does the caching: https://code.djangoproject.com/browser/django/trunk/django/db/models/base.py#L91
Back to Top