#37113: Don't let cache backends swallow explicit errors in cache arguments
-----------------------------------------------+--------------------------
               Reporter:  jodizzle             |          Owner:  jodizzle
                   Type:  Uncategorized        |         Status:  assigned
              Component:  Core (Cache system)  |        Version:  dev
               Severity:  Normal               |       Keywords:
           Triage Stage:  Unreviewed           |      Has patch:  0
    Needs documentation:  0                    |    Needs tests:  0
Patch needs improvement:  0                    |  Easy pickings:  0
                  UI/UX:  0                    |
-----------------------------------------------+--------------------------
 The following [https://docs.djangoproject.com/en/6.0/topics/cache/#cache-
 arguments cache arguments]

 - `TIMEOUT`
 - `OPTIONS['MAX_ENTRIES']`
 - `OPTIONS['CULL_FREQUENCY']`

 are integer values that are handled by
 
[https://github.com/django/django/blob/3e4e0db66961a48a080ff3ff91f6c0d954261366/django/core/cache/backends/base.py#L66
 `BaseCache`] such that non-integer values are ignored and fallback to the
 default.  For example:

 - If a Django app didn't set a `TIMEOUT` for the caching backend, the
 cache timeout would be set to `300`, the default;
 - If a Django app set a `TIMEOUT` for the caching backend to `0`, the
 cache timeout would be set to `0`, as expected;
 - If a Django app somehow set a `TIMEOUT` of `'abc'`, the cache timeout
 would be set to `300`.

 My feeling is that the third behavior is wrong.  If any of these settings
 can't be parsed by Django as an integer, Django should throw an error to
 make it clear to the user that the app is improperly configured.

 I'll also note:
 - This behavior does not seem to be documented.  The cache arguments
 section of the documentation mentions the default values, and makes it
 fairly clear that the settings are for integers, but it doesn't mention
 that inappropriate values are forced to the defaults.
 - This behavior does not seem to be tested in the test suite.  If the
 error swallowing logic is removed, the test suite still passes.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37113>
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 visit 
https://groups.google.com/d/msgid/django-updates/0107019e43328372-1d364f78-f394-4625-a9bc-95d79fed3598-000000%40eu-central-1.amazonses.com.

Reply via email to