fix: guard against unknown fields in the snapd JSON response payload - #45
Open
cgoesche wants to merge 3 commits into
Open
fix: guard against unknown fields in the snapd JSON response payload#45cgoesche wants to merge 3 commits into
cgoesche wants to merge 3 commits into
Conversation
…payload Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
If snapd returns a JSON response that contains fields not registered for the SnapdResponse dataclass, the Snapdresponse __init__() will error out and not instantiate a usable object. To avoid this problem we can filter out all JSON response fields that are currently not set for our dataclass and silently ignore them. Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
cgoesche
force-pushed
the
fix_unknown_json_field_err
branch
from
August 6, 2026 17:04
b25af8d to
ba33cca
Compare
Author
|
Hey @Perfect5th @st3v3nmw just wanted to know if you have time to review this ? |
st3v3nmw
self-requested a review
August 17, 2026 07:34
Member
|
Hi @cgoesche, I'll review this later today or tomorrow. |
st3v3nmw
previously approved these changes
Aug 18, 2026
st3v3nmw
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks.
Could you also add a small unit test for the filtering behavior?
cgoesche
force-pushed
the
fix_unknown_json_field_err
branch
from
August 18, 2026 15:37
1cb7b11 to
5218a74
Compare
Author
Added a simple unit test :) |
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.
I am currently refactoring a
snapcommand line wrapper where I am replacing direct subprocess calls withsnap-http's lib API, which makes the code cleaner and more efficient. In the process I encountered aSnapdresponsedataclass instantiation bug when making a call to thev2/findendpoint with the following messageSnapdresponse.__init__() got an unexpected keyword argument 'suggested_currency'.After looking through the codebase I could see that the dataclass was missing a field for the
suggested-currencyJSON field that this particular (maybe other) snapd API endpoint returns.Adding the missing data field made sense for this particular case, however if there are more such endpoints with undocumented response fields we might want to filter out any currently unregistered dataclass fields from the JSON payload until they are added, no ?
Let me know your thoughts on this :)