#19221: Cache keys can't be integers
-------------------------------------+-------------------------------------
     Reporter:  Mark Hughes          |                    Owner:  Abhimanyu
                                     |  Singh Negi
         Type:  Bug                  |                   Status:  closed
    Component:  Core (Cache system)  |                  Version:  dev
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mike Edmunds):

 * needs_better_patch:  1 => 0
 * resolution:   => fixed
 * status:  assigned => closed
 * summary:  Check that cache keys are string => Cache keys can't be
              integers

Comment:

 I am closing this ticket as "fixed." The original problem was resolved by
 the "provisional" changes in comment:8, which in the intervening 13
 years^1^ have become Django's de facto standard.

 In practice, Django ''does'' allow non-string cache keys (and key
 prefixes), and its default `KEY_FUNCTION` will coerce those to strings if
 possible or error if not. It's maybe not ideal that `42` and `"42"` become
 the same cache item, but that's how it's worked for over a decade (without
 additional bug reports that I could find).

 There are likely projects using bytes or other non-str-coercible key types
 with custom key functions. Any plan to deprecate non-str keys would need
 to account for those uses. (If there's still a desire to restrict keys to
 strings, a Django Forum discussion or new-features proposal is probably
 the best way to proceed.)

 The docs inconsistency Balazs Endresz pointed out in comment:16 (in the
 settings reference vs caches topic) is still there in the 6.0 docs. I've
 opened a "Refs !#19221" PR [https://github.com/django/django/pull/20695
 #20695] to clean that up.

 -----

 ^1^ Also in the past 13 years: Django has dropped support for Python 2.7
 (so str and bytes have stabilized), Python has added f-strings (making
 implicit str coercion commonplace—without Python turning into PHP 😀),
 Django's process for design decisions has evolved multiple times, and this
 ticket has become an attractive nuisance for prospective first-time
 contributors.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/19221#comment:27>
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/0107019c583e7201-6651046f-4936-456c-b6de-1403cc3299cf-000000%40eu-central-1.amazonses.com.

Reply via email to