#35141: CACHE_MIDDLEWARE_SECONDS can be set to a float but has to be an int
-------------------------------------+-------------------------------------
Reporter: Alexander Lazarević | Owner: Alexander
Type: | Lazarević
Cleanup/optimization | Status: assigned
Component: Core (Cache system) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Alexander Lazarević):
Ok in #35041 it's been said that
> ... however we cannot add type checks for all settings. It's documented
as integer and Django crashes when you use it incorrectly, so it's hard to
miss.
Well currently a float for CACHE_MIDDLEWARE_SECONDS will just work, but
produce the wrong value for max_age, which is easy to miss.
But looking forward I have a draft PR for #27225 that will make Django
crash, when CACHE_MIDDLEWARE_SECONDS is a float. So this would be a harsh
indicator that the setting for CACHE_MIDDLEWARE_SECONDS is wrong.
'''With that I'm suggesting I change the PR for this ticket to "just" fix
the comment and the setting in the testcase? What do you think?'''
Regardless of that, maybe two more thoughts:
> Certainly, but I wonder if it's Django's responsibility (and any third-
party code that uses the setting) to silently correct such a mistake.
In this case I would rather want Django sillently do the right thing than
silently do the wrong thing.
> I'm not sure we want to go down the path of casting every integer
setting?
I think we shouldn't make the perfect (type checking every setting) the
enemy of the good (fixing one particular problem with one setting). In
general.
--
Ticket URL: <https://code.djangoproject.com/ticket/35141#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018d43a177a1-7a144c68-36b9-4e06-bbbe-f905ccf7fb5c-000000%40eu-central-1.amazonses.com.