﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37529	ValueError for timeout=0 with pylibmc 1.8.0	Jacob Walls	Jacob Walls	"pylibmc 1.8.0 from 2026-11-18 raises `ValueError: time must not be negative` during `cache.tests.PyLibMCCacheTests.test_zero_timeout`.

[https://github.com/lericson/pylibmc/releases/tag/1.8.0 Release notes] and [https://github.com/lericson/pylibmc/issues/202 PR]

Django interprets a timeout of 0 as ""immediately expire"". This was re-confirmed when adding the redis backend, see 7f33c1e22dbc34a7afae7967783725b10f1f13b1:

{{{#!py
        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:

{{{#!py
        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."	Bug	assigned	Core (Cache system)	6.1	Release blocker				Unreviewed	0	0	0	0	0	0
