Fix core dependency constraint blocking compatible plugin upgrades#6422
Open
he-yufeng wants to merge 2 commits intoAstrBotDevs:masterfrom
Open
Fix core dependency constraint blocking compatible plugin upgrades#6422he-yufeng wants to merge 2 commits intoAstrBotDevs:masterfrom
he-yufeng wants to merge 2 commits intoAstrBotDevs:masterfrom
Conversation
The core constraints mechanism pins dependencies to the exact installed version (e.g. aiosqlite==0.21.0), which prevents plugins from pulling in newer compatible versions. A plugin requiring aiosqlite>=0.22.1 fails even though 0.22.1 is backward-compatible with the core's >=0.21.0 requirement. Change the constraint from == to >= so that: - Downgrades below the installed version are still blocked (protection) - Plugins can require newer versions when compatible (flexibility) Fixes AstrBotDevs#6420
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Changing
==to>=broadens the allowed range considerably; consider whether you also need an upper bound (e.g.<next major) or another mechanism to guard against potentially breaking future major versions being pulled in by plugins. - The bare
except Exception: continuearound constraint generation can hide unexpected issues; if feasible, narrow the exception type or at least log the exception so that silent failures in constraint building are observable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Changing `==` to `>=` broadens the allowed range considerably; consider whether you also need an upper bound (e.g. `<` next major) or another mechanism to guard against potentially breaking future major versions being pulled in by plugins.
- The bare `except Exception: continue` around constraint generation can hide unexpected issues; if feasible, narrow the exception type or at least log the exception so that silent failures in constraint building are observable.
## Individual Comments
### Comment 1
<location path="astrbot/core/utils/core_constraints.py" line_range="83-85" />
<code_context>
name = canonicalize_distribution_name(req.name)
if name in installed:
- constraints.append(f"{name}=={installed[name]}")
+ # Use >= instead of == so plugins can pull in newer compatible
+ # versions while still preventing downgrades below what's installed.
+ constraints.append(f"{name}>={installed[name]}")
except Exception:
continue
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Relaxing from == to >= may undermine reproducibility and allow incompatible major upgrades.
Switching from an exact pin to a lower bound means different environments may resolve to different versions over time, which weakens reproducibility and can allow breaking major upgrades (e.g., `1.5` installed but `>=1.5` allows `2.x`). If the goal is to avoid downgrades while allowing safe upgrades, consider either a bounded range like `>=installed,<next_major` or keeping strict pins here and letting plugins declare more permissive requirements. Also verify whether this change is consistent with any expectations of deterministic resolution for this function.
Suggested implementation:
```python
if name in installed:
# Use a bounded range (>=installed,<next_major) so that:
# - we prevent downgrades below the currently installed version
# - we avoid unbounded major upgrades that may be incompatible
installed_version = installed[name]
try:
major = int(str(installed_version).split(".")[0])
except (ValueError, TypeError):
# If we cannot parse a simple major version, fall back to
# an exact pin to preserve deterministic behavior.
constraints.append(f"{name}=={installed_version}")
else:
next_major = major + 1
constraints.append(f"{name}>={installed_version},<{next_major}")
```
Depending on the rest of the codebase, you may also want to:
1. Update or add tests that assert the constraint format, e.g. installed `1.5.2` leads to `>=1.5.2,<2`.
2. Ensure any documentation or comments describing this function’s determinism/reproducibility are updated to reflect the bounded-range behavior.
</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
|
测试了吗 |
Instead of unbounded >=, use >=installed,<next_major so plugins can upgrade within the same major version but won't accidentally pull in breaking major releases (e.g. 1.5 installed won't allow 2.x). Falls back to exact pin if major version can't be parsed.
Contributor
Author
|
Tested locally — here's what I verified: from packaging.requirements import Requirement
# simulate installed versions
installed = {"aiohttp": "3.9.1", "pydantic": "2.5.0", "numpy": "0.9.3"}
for ver in installed.values():
try:
next_major = int(str(ver).split(".")[0]) + 1
except (ValueError, TypeError):
print(f"==fallback")
else:
print(f">={ver},<{next_major}")
# Output:
# >=3.9.1,<4
# >=2.5.0,<3
# >=0.9.3,<1Also updated to use bounded |
faf411f to
0068960
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The core dependency protection mechanism pins dependencies to the exact installed version using
==:This prevents plugins from installing newer compatible versions. For example, a plugin requiring
aiosqlite>=0.22.1fails with:Even though
0.22.1 >= 0.21.0and is backward-compatible.Fix
Change
==to>=in the constraint generation:This preserves the protection against downgrades (plugins can't install older versions than what's running) while allowing compatible upgrades.
Fixes #6420
Summary by Sourcery
Bug Fixes: