lib.Uri: Fix stale cache in __new_with_path() #74

Merged
Jan Lindemann merged 1 commit from jan/fix/20260820-lib-uri-fix-stale-cache-in-new-with-path into master 2026-08-20 07:58:38 +02:00 AGit

lib.Uri: Fix stale cache in __new_with_path()

__new_with_path() builds the new Uri by deep-copying self and then replacing __string. A deep copy, however, also carries over any cached_property values that were already computed on self (e.g. __p, path, scheme, full), so once __string changes, they stay stale: for a Uri on which any of those properties had been accessed before, new_add_path() and new_replace_path() returned objects whose to_string() showed the new string while path(), hostname(), full() and friends still described the old one.

Build a fresh instance with object.new() and initialize its three basic attributes instead of copying, so no computed cached state can be inherited.

#### lib.Uri: Fix stale cache in __new_with_path() __new_with_path() builds the new Uri by deep-copying self and then replacing __string. A deep copy, however, also carries over any cached_property values that were already computed on self (e.g. __p, path, scheme, full), so once __string changes, they stay stale: for a Uri on which any of those properties had been accessed before, new_add_path() and new_replace_path() returned objects whose to_string() showed the new string while path(), hostname(), full() and friends still described the old one. Build a fresh instance with object.__new__() and initialize its three basic attributes instead of copying, so no computed cached state can be inherited.
lib.Uri: Fix stale cache in __new_with_path()
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m4s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m6s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m13s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 3m53s
CI / Packaging test (push) Successful in 0s
9a953d0017
__new_with_path() builds the new Uri by deep-copying self and then
replacing __string. A deep copy, however, also carries over any
cached_property values that were already computed on self (e.g. __p,
path, scheme, full), so once __string changes, they stay stale: for a
Uri on which any of those properties had been accessed before,
new_add_path() and new_replace_path() returned objects whose
to_string() showed the new string while path(), hostname(), full() and
friends still described the old one.

Build a fresh instance with object.__new__() and initialize its three
basic attributes instead of copying, so no computed cached state can
be inherited.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M and pi.dev
Signed-off-by: Jan Lindemann <jan@janware.com>
Jan Lindemann scheduled this pull request to auto merge when all checks succeed 2026-08-20 07:50:22 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
janware/jw-pkg!74
No description provided.