Opened 29 minutes ago
#37529 assigned Bug
ValueError for timeout=0 with pylibmc 1.8.0
| Reported by: | Jacob Walls | Owned by: | Jacob Walls |
|---|---|---|---|
| Component: | Core (Cache system) | Version: | 6.1 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
pylibmc 1.8.0 from 2026-11-18 raises ValueError: time must not be negative during cache.tests.PyLibMCCacheTests.test_zero_timeout.
Release notes and PR
Django interprets a timeout of 0 as "immediately expire". This was re-confirmed when adding the redis backend, see 7f33c1e22dbc34a7afae7967783725b10f1f13b1:
elif int(timeout) == 0: # Other cache backends treat 0 as set-and-expire. To achieve this # in memcache backends, a negative timeout must be passed. timeout = -1
I suggest we adapt the pylibmc backend to continue supporting this contract even when 1.8.0 is in use by adjusting it to delete() instead when the timeout is zero, following the example of the redis backend:
if timeout == 0: client.delete(key) else: client.set(key, value, ex=timeout)
This will also have the benefit of fixing the semantic when binary mode is enabled, as apparently negative values meant cache forever (and indeed this is why the ValueError was added to pylibmc).
Suggest backporting to 6.1. Another commit could make pylibmc 1.7 the minimum for the main branch as it's the first version to declare support for Python 3.12, but won't backport it.