Fix Proxmox VE sensor crashes due to missing API fields#168071
Fix Proxmox VE sensor crashes due to missing API fields#168071irishpadres wants to merge 9 commits intohome-assistant:devfrom
Conversation
There was a problem hiding this comment.
Hello @irishpadres,
When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es).
The commits that are missing a linked GitHub account are the following:
b581592aa7ecf1c87fbb7cb94f1a4e0de5698c4d- This commit has something that looks like an email address (kevin@tahoe.kobrien.net). Maybe try linking that to GitHub?.
Unfortunately, we are unable to accept this pull request until this situation is corrected.
Here are your options:
-
If you had an email address set for the commit that simply wasn't linked to your GitHub account you can link that email now and it will retroactively apply to your commits. The simplest way to do this is to click the link to one of the above commits and look for a blue question mark in a blue circle in the top left. Hovering over that bubble will show you what email address you used. Clicking on that button will take you to your email address settings on GitHub. Just add the email address on that page and you're all set. GitHub has more information about this option in their help center.
-
If you didn't use an email address at all, it was an invalid email, or it's one you can't link to your GitHub, you will need to change the authorship information of the commit and your global Git settings so this doesn't happen again going forward. GitHub provides some great instructions on how to change your authorship information in their help center.
- If you only made a single commit you should be able to run
(substituting "Author Name" and "
git commit --amend --author="Author Name <email@address.com>"email@address.com" for your actual information) to set the authorship information. - If you made more than one commit and the commit with the missing authorship information is not the most recent one you have two options:
- You can re-create all commits missing authorship information. This is going to be the easiest solution for developers that aren't extremely confident in their Git and command line skills.
- You can use this script that GitHub provides to rewrite history. Please note: this should be used only if you are very confident in your abilities and understand its impacts.
- Whichever method you choose, I will come by to re-check the pull request once you push the fixes to this branch.
- If you only made a single commit you should be able to run
We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community.
Thanks, I look forward to checking this PR again soon! ❤️
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @Corbeno, @erwindouna, @CoMPaTech, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes Proxmox VE sensor crashes when API responses omit expected fields by making sensor value extraction resilient and adding regression tests for incomplete/zero-value payloads.
Changes:
- Updated Proxmox node/VM/container/storage sensor
value_fnaccessors to usedict.get()and guard missing keys. - Added safer handling for missing backup timestamps (and duration calculation).
- Added new test coverage for incomplete API responses and a zero-capacity storage pool.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
homeassistant/components/proxmoxve/sensor.py |
Makes sensor value functions tolerant of missing fields to prevent KeyError crashes. |
tests/components/proxmoxve/test_sensor_missing_data.py |
Adds regression tests to ensure missing/zero fields don’t crash and yield unknown/safe values. |
b581592 to
a37623e
Compare
|
I have addressed the feedback from the automated review:
Everything is now verified passing with local tests. |
a37623e to
9525a74
Compare
9525a74 to
751dca8
Compare
751dca8 to
6d331c5
Compare
Update all sensor definitions (Node, VM, Container, and Storage) to safely handle missing keys in the Proxmox API response by using dict.get(). This prevents KeyError crashes for entities where certain fields (like used_fraction, cpu, or memory) may be omitted. Added tests/components/proxmoxve/test_sensor_missing_data.py to verify robust handling of incomplete API data.
f9b2330 to
2433faf
Compare
- Return None (unknown) from node status binary sensor when status field is missing, instead of False (offline) - Return False from backup status binary sensor when no backups exist (not a problem), and None only when backup entry has no status field - Remove exists_fn from storage sensors; always create entities and return None when fields are transiently missing to avoid permanent loss of entities on partial first refresh - Update tests to assert entities exist and report STATE_UNKNOWN instead of asserting entity_id is None - Add assert state is not None guards throughout missing-data tests
- Return None (unknown) from node status binary sensor when status field is missing, instead of False (offline) - Return False from backup status binary sensor when no backups exist (not a problem), and None only when backup entry has no status field - Remove exists_fn from storage sensors; always create entities and return None when fields are transiently missing to avoid permanent loss of entities on partial first refresh - Fix storage binary sensors (active, enabled, shared) to return None when their field is absent, instead of False - Update tests to assert entities exist and report STATE_UNKNOWN instead of asserting entity_id is None - Add assert state/entity_id is not None guards in missing-data tests - Add photo NFS storage fixture entry (active=0, no used_fraction) reflecting real Proxmox API response for an offline NFS mount - Reference photo storage in missing-data test instead of synthetic zero_pool entry Fixes home-assistant#168554
| key="status", | ||
| translation_key="status", | ||
| state_fn=lambda data: data["status"] == VM_CONTAINER_RUNNING, | ||
| state_fn=lambda data: data.get("status") == VM_CONTAINER_RUNNING, |
There was a problem hiding this comment.
Return None (unknown) when the container status field is missing instead of treating it as False, so a partial Proxmox API response doesn’t incorrectly mark the container as stopped.
| state_fn=lambda data: data.get("status") == VM_CONTAINER_RUNNING, | |
| state_fn=lambda data: ( | |
| status == VM_CONTAINER_RUNNING | |
| if (status := data.get("status")) is not None | |
| else None | |
| ), |
erwindouna
left a comment
There was a problem hiding this comment.
Tests are failing, can you please look into them? :)
The test strips 'used' from all storage entries to test missing-data robustness, then incorrectly expected float(0.0) for the photo storage used sensor. Since the field is stripped, the state is 'unknown'.
Proposed change
This PR improves robustness of the Proxmox VE integration by ensuring sensors handle missing or partial API fields gracefully rather than crashing or reporting incorrect state.
Architectural approach
All sensors now use `dict.get()` instead of direct key access. Rather than gating entity creation on the presence of API fields (which permanently prevents entity creation if the first coordinator refresh returns partial data), entities are always created and return `None` (reported as `STATE_UNKNOWN`) when data is absent.
Key changes:
Note: snapshot tests will need regenerating in CI (`--snapshot-update`) due to the new storage fixture entry.
Type of change
Additional information
Checklist