fix: ignore different URL in cache staleness check#10699
Merged
radoering merged 3 commits intopython-poetry:mainfrom Jan 20, 2026
Merged
fix: ignore different URL in cache staleness check#10699radoering merged 3 commits intopython-poetry:mainfrom
radoering merged 3 commits intopython-poetry:mainfrom
Conversation
Reviewer's GuideAdjusts the provider’s cache staleness check to ignore URL differences between file entries and only compare filename+hash, and adds tests to ensure repository refresh is not triggered when only URLs change. Sequence diagram for cache staleness check in complete_packagesequenceDiagram
participant Provider
participant DependencyPackage
participant Package
participant PoolPackage
participant Repository
Provider->>DependencyPackage: complete_package(dependency_package)
DependencyPackage-->>Provider: dependency, package
Provider->>Repository: get_package(dependency)
Repository-->>Provider: pool_package
alt package.files is not empty
Provider->>Provider: pkg_list = _files_list_for_cmp(package.files)
Provider->>Provider: pool_list = _files_list_for_cmp(pool_package.files)
alt pkg_list != pool_list
Provider->>Repository: refresh package cache
Repository-->>Provider: updated pool_package
else pkg_list == pool_list
Provider-->>Provider: skip refresh (URL differences ignored)
end
else package.files is empty
Provider-->>Provider: no staleness check
end
Provider-->>DependencyPackage: updated DependencyPackage
Updated class diagram for Provider cache staleness logicclassDiagram
class Provider {
+complete_package(dependency_package: DependencyPackage) DependencyPackage
+_files_list_for_cmp(files: Sequence_PackageFile) list_string
}
class PackageFile {
+file: string
+hash: string
+url: string
}
class DependencyPackage
class Package {
+files: Sequence_PackageFile
}
class PoolPackage {
+files: Sequence_PackageFile
}
Provider --> DependencyPackage
DependencyPackage --> Package
DependencyPackage --> PoolPackage
Package --> PackageFile
PoolPackage --> PackageFile
Provider ..> PackageFile : uses_in_files_list_for_cmp
Provider ..> Package : reads_files
Provider ..> PoolPackage : reads_files
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Tasssadar
commented
Jan 20, 2026
Comment on lines
+496
to
+498
| if package.files and self._files_list_for_cmp( | ||
| package.files | ||
| ) != self._files_list_for_cmp(pool_package.files): |
Contributor
Author
There was a problem hiding this comment.
The original check ended up comparing data like this:
{'file': 'pkg.whl', 'hash': 'sha256:abc...'}
{'file': 'pkg.whl', 'hash': 'sha256:abc...', 'url': 'someurl'}
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
_files_list_for_cmp, concatenatingf["file"] + f["hash"]risks collisions and may break ifhashis missing orNone; consider using a tuple(f["file"], f.get("hash"))or a delimited string and handling absent hashes explicitly. - The new
_files_list_for_cmphelper is typed asSequence[PackageFile], but relies on__getitem__with string keys; ifPackageFileisn't a mapping type everywhere, tightening or adjusting this type to reflect the expected mapping-like interface would make misuse harder.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_files_list_for_cmp`, concatenating `f["file"] + f["hash"]` risks collisions and may break if `hash` is missing or `None`; consider using a tuple `(f["file"], f.get("hash"))` or a delimited string and handling absent hashes explicitly.
- The new `_files_list_for_cmp` helper is typed as `Sequence[PackageFile]`, but relies on `__getitem__` with string keys; if `PackageFile` isn't a mapping type everywhere, tightening or adjusting this type to reflect the expected mapping-like interface would make misuse harder.
## Individual Comments
### Comment 1
<location> `src/poetry/puzzle/provider.py:456-463` </location>
<code_context>
]
+ @staticmethod
+ def _files_list_for_cmp(files: Sequence[PackageFile]) -> list[str]:
+ """
+ :return: A list of strings representing the files and their hashes, for
+ the purpose of comparing the file list to another one.
+ We only use file+hash, because that's what uniquely identifies the file,
+ the other properties (like URL) are not relevant.
+ """
+ return sorted(f["file"] + f["hash"] for f in files)
+
def complete_package(
</code_context>
<issue_to_address>
**issue (bug_risk):** Avoid concatenating file and hash without a separator to prevent potential collisions.
Using `f["file"] + f["hash"]` risks ambiguous keys if different `(file, hash)` pairs produce the same concatenated string. Instead, return and sort tuples so the comparison is unambiguous:
```python
return sorted((f["file"], f["hash"]) for f in files)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Member
|
pre-commit.ci autofix |
radoering
approved these changes
Jan 20, 2026
nothing-991
pushed a commit
to nothing-991/python-poetry
that referenced
this pull request
Feb 3, 2026
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves: #10698
Only the file name and hash are relevant when checking for the staleness, no need to check for any other attributes.
Summary by Sourcery
Adjust package cache staleness checks to treat file URL changes as non-stale while still detecting changes in file names and hashes.
Bug Fixes:
Tests: