Opened 13 months ago

Closed 12 months ago

Last modified 9 months ago

#31802 closed Cleanup/optimization (fixed)

Add system check for SITE_ID.

Reported by: Gagan Deep Owned by: Parth Verma
Component: contrib.sites Version: dev
Severity: Normal Keywords: sites, cache
Cc: me@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The "sites" framework requires to set a SITE_ID to specify the database ID of the Site object associated with that particular settings file. From the documentation, it can be interpreted that it should be an integer. But, it can also be set to a string literal('1'). I know this is wrong, but the Django accepted it and worked with it anyway without showing any warning or error.

The problem arose with SITE_CACHE. It was not getting invalidated when the Site object is updated. The reason is the code which handles invalidation uses primary key of instance object which will be an integer. Therefore, the cache is never invalidated.

try:
    del SITE_CACHE[instance.pk]
except KeyError:
    pass

Please see complete code on GitHub.

Since working of an element of Django is dependent on this setting, I suggest that there be a validation test for SITE_ID.

Change History (7)

comment:1 Changed 13 months ago by Adam Johnson

Part of the problem here is that Site.objects.get(pk=some_string) works because the database uses SQL implicit type conversion to cast the string, but we need a consistent value within Python.

If it's only the site cache that's affected we could make SITE_CACHE a subclass of dict that casts keys but that seems like overengineering when a system check would provide enough validation at the boundary.

Last edited 13 months ago by Mariusz Felisiak (previous) (diff)

comment:2 Changed 13 months ago by Mariusz Felisiak

Summary: Validation for "SITE_ID" settingAdd system check for SITE_ID.
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization
Version: 3.0master

... it can be interpreted that it should be an integer.

It's clearly stated in docs: "The ID, as an integer, ..." but I agree that we can add a system check, e.g.

sites.E003: ``SITE_ID`` must be an integer.

comment:3 Changed 13 months ago by Parth Verma

Owner: changed from nobody to Parth Verma
Status: newassigned

comment:4 Changed 12 months ago by Mariusz Felisiak

Has patch: set
Needs documentation: set
Needs tests: set

comment:5 Changed 12 months ago by Mariusz Felisiak

Needs documentation: unset
Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:6 Changed 12 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 41065cf:

Fixed #31802 -- Added system check for non-integer SITE_ID.

comment:7 Changed 9 months ago by Gagan Deep

It's clearly stated in ​docs: "The ID, as an integer, ..."

I must have overlooked that. Thanks for bringing it. :)

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