Opened 15 years ago

Closed 15 years ago

#12063 closed (wontfix)

Ensure SITE_CACHE uses integers as key values

Reported by: Patryk Zawadzki Owned by: nobody
Component: Contrib apps Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently django.contrib.sites.models.SiteManager.get_current just takes whatever value SITE_ID is set to and shoves it into the cache. This leads to strange results if you replace the integer value with a proxy object that implements __int__().

Whenever you want to return a different value at runtime (say you want to serve different content depending on the time of day or the hostname), you currently have to clear the cache as you end up with the following dict:

SITE_CACHE = {
    <Your proxy object>: <The first Site object ever used>,
}

The second time Django will just use the cache (as the proxy is equal to itself even if the value returned by __int__() changed).

Yes, I know altering settings at run time is not really encouraged but being able to proxy SITE_ID and alter the value using middleware is useful when dealing with dynamic subdomains (like customer1.example.com) and the change is both tiny and backwards-compatible.

Attachments (1)

django-site-cache.patch (678 bytes ) - added by Patryk Zawadzki 15 years ago.
Same patch in svn diff format

Download all attachments as: .zip

Change History (2)

by Patryk Zawadzki, 15 years ago

Attachment: django-site-cache.patch added

Same patch in svn diff format

comment:1 by Russell Keith-Magee, 15 years ago

Resolution: wontfix
Status: newclosed

I'm not convinced that a dynamic SITE_ID is the right way to tackle this class of problem. I'm going to mark this wontfix; please raise this on django-dev if you want to argue your position.

Note: See TracTickets for help on using tickets.
Back to Top