Skip to content

apt_info: don't crash where phasing_applied is missing - #272

Open
Bierchermuesli wants to merge 1 commit into
prometheus-community:masterfrom
Bierchermuesli:apt-info-phasing-compat
Open

Bierchermuesli wants to merge 1 commit into
prometheus-community:masterfrom
Bierchermuesli:apt-info-phasing-compat

Conversation

@Bierchermuesli

Copy link
Copy Markdown

apt_info.py aborts on every run where python-apt predates the phased updates API, which it has exposed since 2.7.11:

File "apt_info.py", line 68, in <setcomp>
  if p.is_upgradable and not p.phasing_applied and p.name not in exclusions
AttributeError: 'Package' object has no attribute 'phasing_applied'

_write_pending_upgrades is the first writer called, so the script exits before emitting anything — affected hosts report no apt metrics at all, not just no pending-upgrade count. Introduced in 9784008 (#220), which added the filter without a guard.

python-apt phasing_applied
Debian 12 bookworm 2.6.0 ✗ (LTS to 2028-06)
Ubuntu 22.04 jammy 2.4.0 ✗ (supported to 2027-04)
Ubuntu 24.04 noble 2.7.7ubuntu* ✓ backported
Debian 13, Ubuntu 25.04+ 3.0.0+ ✓

This probes for the attribute rather than comparing versions, because Ubuntu backported the API into noble's 2.7.7 — a version check would wrongly disable phasing on the distro where it matters most. The hasattr is resolved once at import, not per package. Where it's missing, every upgrade counts as unphased, which is what the script did before 9784008.

#269 also removes these calls, but drops the feature outright and is a much larger change. This keeps it wherever the API exists and should be easy to drop if that lands first.

flake8 clean. Verified on python-apt 3.1.0, and with phasing_applied deleted from the class to simulate an older release.

python-apt exposes the phased updates API since 2.7.11. On Debian 12
(2.6.0) and Ubuntu 22.04 (2.4.0) p.phasing_applied raises AttributeError
for every package, and since _write_pending_upgrades runs first the script
exits before writing any metric -- those hosts report nothing at all.

Probe for the attribute rather than comparing versions: Ubuntu 24.04
backported the API into its 2.7.7, so a version check would wrongly disable
phasing there. Where the attribute is missing, treat every upgrade as
unphased, which is what the script did before 9784008.

Signed-off-by: Stefan Grosser <13567009+Bierchermuesli@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant