#30625: DatabaseCache backend raises TypeError if get/delete received key as integer. ---------------------------------+------------------------------------ Reporter: Hiroki Kiyohara | Owner: nobody Type: Bug | Status: new Component: Documentation | Version: 2.2 Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ---------------------------------+------------------------------------ Description changed by LemonAndroid:
Old description: > After Django 2.2, DatabaseCache backend will raise TypeError when > get/delete method received integer key. > > {{{ > >>> cache = caches["..."] > <django.core.cache.backends.db.DatabaseCache object at 0x7f2d5ce37ac8> > >>> cache.get(1) > Traceback (most recent call last): > File "/usr/lib/python3.7/code.py", line 90, in runcode > exec(code, self.locals) > File "<console>", line 1, in <module> > File "/home/hirokiky/.../venv/lib/python3.7/site- > packages/django/core/cache/backends/db.py", line 52, in get > return self.get_many([key], version).get(key, default) > File "/home/hirokiky/.../venv/lib/python3.7/site- > packages/django/core/cache/backends/db.py", line 60, in get_many > self.validate_key(key) > File "/home/hirokiky/.../venv/lib/python3.7/site- > packages/django/core/cache/backends/base.py", line 245, in validate_key > if len(key) > MEMCACHE_MAX_KEY_LENGTH: > }}} > > I know it's not a bug. Because we should pass key as string. > > > key should be a str, and value can be any picklable Python object. > > https://docs.djangoproject.com/en/2.2/topics/cache/#basic-usage > > Before Django 2.2, key argument had been formatted by `make_key` method, > and it would convert integer to string. > But now Django 2.2 will call `validate_key` before `make_key`, so it will > raise TypeError if you pass integer key. > > I think describing about this change on Django 2.2 release note is better > (as small backward incompatible change). > > https://docs.djangoproject.com/en/2.2/releases/2.2/ > > Note: This behaviour will happen after this optimization. > https://code.djangoproject.com/ticket/29584 New description: Ruby on Rails -- -- Ticket URL: <https://code.djangoproject.com/ticket/30625#comment:3> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.31d7e24a224a2578d1ba1f11aef95c4a%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.