Skip to content

fix: guard against unknown fields in the snapd JSON response payload - #45

Open
cgoesche wants to merge 3 commits into
canonical:mainfrom
cgoesche:fix_unknown_json_field_err
Open

fix: guard against unknown fields in the snapd JSON response payload#45
cgoesche wants to merge 3 commits into
canonical:mainfrom
cgoesche:fix_unknown_json_field_err

Conversation

@cgoesche

@cgoesche cgoesche commented Aug 5, 2026

Copy link
Copy Markdown

I am currently refactoring a snap command line wrapper where I am replacing direct subprocess calls with snap-http's lib API, which makes the code cleaner and more efficient. In the process I encountered a Snapdresponse dataclass instantiation bug when making a call to the v2/find endpoint with the following message Snapdresponse.__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-currency JSON 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 :)

…payload

Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
@cgoesche cgoesche changed the title Fix unknown json field err fix: guard against unknown fields in the snapd JSON response payload Aug 5, 2026
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
cgoesche force-pushed the fix_unknown_json_field_err branch from b25af8d to ba33cca Compare August 6, 2026 17:04
@cgoesche

Copy link
Copy Markdown
Author

Hey @Perfect5th @st3v3nmw just wanted to know if you have time to review this ?

@st3v3nmw
st3v3nmw self-requested a review August 17, 2026 07:34
@st3v3nmw

Copy link
Copy Markdown
Member

Hi @cgoesche, I'll review this later today or tomorrow.

st3v3nmw
st3v3nmw previously approved these changes Aug 18, 2026

@st3v3nmw st3v3nmw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

Could you also add a small unit test for the filtering behavior?

@cgoesche
cgoesche force-pushed the fix_unknown_json_field_err branch from 1cb7b11 to 5218a74 Compare August 18, 2026 15:37
@cgoesche

Copy link
Copy Markdown
Author

Could you also add a small unit test for the filtering behavior?

Added a simple unit test :)

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.

2 participants