Why Does a New Python Request Contain the Previous Request’s Data?
A helper function passes its first test. It collects the warnings for one import and returns the expected result. When a second import runs in the same process, its warning list includes a message from the first. Restarting the service appears to fix the problem, but only until the next request.
One possible cause is a mutable default argument. The diagnostic goal is to find where the unwanted sharing begins, not to assume that every repeated-data symptom has the same explanation.
Check the lifetime of the default object
The Python programming FAQ explains that default argument values are created when the function is defined. A list or dictionary used as a default can therefore retain mutations across calls. For per-call state, the FAQ shows using None and creating the collection inside the function.
Treat this as a question of ownership. Is the collection intended to belong to one request, the caller or the whole service? A function signature that looks convenient should not make that decision implicitly.
Reproduce the issue without external systems
Use two synthetic imports with visibly different identifiers and warnings. Call the helper twice in the same process, omitting the optional collection both times. Inspect the first result again after the second call as well as inspecting the second result.
Keep network calls, files and databases out of this small reproduction. If the shared state appears without them, the investigation can focus on the function and its objects. If it does not, retain the failing end-to-end example and investigate the next boundary rather than declaring the issue solved.
Illustrative example: warnings leak between imports
Suppose import A contains an unrecognized category and import B contains a missing date. The expected results are one category warning for A and one date warning for B. A result for B containing both messages indicates that the warning collection may outlive its intended request.
Also check whether the object returned for A changes after B runs. That reveals a different consequence from merely returning an extra message once: a caller may hold a result that is later altered by unrelated work.
Illustrative example: an explicit collection is intentional
A caller may deliberately supply one list to accumulate warnings across several related files. That can be a valid contract. A correction should preserve this intentional use if the interface promises it.
Test the omitted-argument path and the explicitly supplied collection separately. The repair should not silently stop updating caller-owned state when callers rely on that behavior. If the contract is changing, update the documentation and affected callers together.
Define the ownership contract in plain language
Document whether the function mutates a supplied collection, returns a new collection or does both. Specify whether returned results remain stable after later calls. These promises are more useful to a reviewer than a general statement that the function is “stateless.”
Use an explicit absence check when None means “create new state.” An empty collection supplied by the caller is still a supplied collection; do not treat emptiness as permission to replace it without considering the contract.
If None is itself meaningful input, choose a distinct sentinel for omission and document it. The implementation should distinguish the business meanings rather than collapse them for convenience.
Verify the boundary after the repair
Run the two-request sequence in both orders. Add a third request with no warnings and confirm that its result is empty. Check that later calls do not alter earlier results when stability is promised.
Do not stop at a fresh-process success. The original symptom depended on repeated calls within one process, so the regression check must exercise that lifetime. Also inspect neighboring helpers for the same ownership assumption, without broad unrelated refactoring.
The synthetic test records guide can help create distinguishable inputs without using customer data. Preserve the smallest case that demonstrates the state boundary, and explain in the change review which sharing was accidental and which sharing remains intentional.
Editorial note
Prepared with AI assistance. Primary sources and the FutureOS article inventory were checked on October 26, 2026. Examples are illustrative, not customer results. FutureOS is described as being in prelaunch in its current introduction. This guide does not claim an available product feature, integration or service, and no independent expert review is claimed.




Comments