[Django] #31734: warnings.warn() fails when looping over memcache_key_warnings()

26 views
Skip to first unread message

Django

unread,
Jun 22, 2020, 6:15:53 PM6/22/20
to django-...@googlegroups.com
#31734: warnings.warn() fails when looping over memcache_key_warnings()
-----------------------------------------------+------------------------
Reporter: Rich Rauenzahn | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------------+------------------------
I think I found a bug in cache backends -- while running unit tests I was
getting:

TypeError: 'type' object cannot be interpreted as an integer

I'm not sure why that exact message, but it arises here:


{{{
> .../virtualenv-3.6.8/lib64/python3.6/site-
packages/django/core/cache/backends/base.py(250)validate_key()
248 """
249 for warning in memcache_key_warnings(key):
--> 250 warnings.warn(warning, CacheKeyWarning)
251
252 def incr_version(self, key, delta=1, version=None):

}}}

I think the problem is that for loop is receiving a list of tuples, but
they are interpreted as a list of strings:


{{{
ipdb> key
":1:<redacted but probably invalid for memcache"

# The generator returns tuples of (message, warning type)

ipdb> for x in memcache_key_warnings(key): print(x)
('Cache key contains characters that will cause errors if used with
memcached:
":1:BuildAPI._request:(\'http://buildapi.eng.vmware.com/sb/build/1895757\',
expire=10)"', <class 'django.core.cache.backends.base.CacheKeyWarning'>)

# But "warning" passed to warning.warn() is the tuple...

ipdb> warning
('Cache key contains characters that will cause errors if used with
memcached:
":1:BuildAPI._request:(\'http://buildapi.eng.vmware.com/sb/build/1895757\',
expire=10)"', <class 'django.core.cache.backends.base.CacheKeyWarning'>)
ipdb>
}}}

I think it should be passing warning.warn(warning[0], warning[1]) or
warning.warn(*warning)

Django 2.2.13 is what I am using.

--
Ticket URL: <https://code.djangoproject.com/ticket/31734>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 22, 2020, 6:19:58 PM6/22/20
to django-...@googlegroups.com
#31734: warnings.warn() fails when looping over memcache_key_warnings()
-------------------------------------+-------------------------------------

Reporter: Rich Rauenzahn | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Rich Rauenzahn):

I made the change locally (i.e., warnings.warn(*warning)) and now properly
get:

ipdb>
virtualenv-3.6.8/lib64/python3.6/site-
packages/django/core/cache/backends/base.py:250: CacheKeyWarning: Cache


key contains characters that will cause errors if used with memcached:

":1:<redacted but invalid>"
warnings.warn(*warning)

--
Ticket URL: <https://code.djangoproject.com/ticket/31734#comment:1>

Django

unread,
Jun 22, 2020, 6:21:58 PM6/22/20
to django-...@googlegroups.com
#31734: warnings.warn() fails when looping over memcache_key_warnings()
-------------------------------------+-------------------------------------

Reporter: Rich Rauenzahn | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Rich Rauenzahn:

Old description:

New description:

I think I found a bug in cache backends -- while running unit tests I was
getting:

TypeError: 'type' object cannot be interpreted as an integer

I'm not sure why that exact message, but it arises here:


{{{
> .../virtualenv-3.6.8/lib64/python3.6/site-
packages/django/core/cache/backends/base.py(250)validate_key()
248 """
249 for warning in memcache_key_warnings(key):
--> 250 warnings.warn(warning, CacheKeyWarning)
251
252 def incr_version(self, key, delta=1, version=None):

}}}

I think the problem is that for loop is receiving a list of tuples, but
they are interpreted as a list of strings:


{{{
ipdb> key
":1:<redacted but probably invalid for memcache"

# The generator returns tuples of (message, warning type)

ipdb> for x in memcache_key_warnings(key): print(x)
('Cache key contains characters that will cause errors if used with
memcached:
":1:BuildAPI._request:(\'http://buildapi.eng.vmware.com/sb/build/1895757\',
expire=10)"', <class 'django.core.cache.backends.base.CacheKeyWarning'>)

# But "warning" passed to warnings.warn() is the tuple...

ipdb> warning
('Cache key contains characters that will cause errors if used with
memcached:
":1:BuildAPI._request:(\'http://buildapi.eng.vmware.com/sb/build/1895757\',
expire=10)"', <class 'django.core.cache.backends.base.CacheKeyWarning'>)
ipdb>
}}}

I think it should be passing warnings.warn(warning[0], warning[1]) or
warnings.warn(*warning)

Django 2.2.13 is what I am using.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/31734#comment:2>

Django

unread,
Jun 22, 2020, 7:11:35 PM6/22/20
to django-...@googlegroups.com
#31734: warnings.warn() fails when looping over memcache_key_warnings()
-------------------------------------+-------------------------------------

Reporter: Rich Rauenzahn | Owner: nobody
Type: Bug | Status: closed

Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #31654 which will be part of 2.2.14
[https://docs.djangoproject.com/en/2.2/releases/2.2.14/ planed to be
released on July first].

--
Ticket URL: <https://code.djangoproject.com/ticket/31734#comment:3>

Reply all
Reply to author
Forward
0 new messages