Skip to content

chore: guard against None dict, always default to {}#177

Merged
kessplas merged 2 commits into
stagingfrom
kessplas/none-guard
May 7, 2026
Merged

chore: guard against None dict, always default to {}#177
kessplas merged 2 commits into
stagingfrom
kessplas/none-guard

Conversation

@kessplas

@kessplas kessplas commented May 1, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available: n/a

Description of changes:

The get() method considers the presence of None as a valid key and won't default to {}.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@kessplas kessplas changed the base branch from main to staging May 1, 2026 19:25
@kessplas kessplas marked this pull request as ready for review May 1, 2026 19:41
if isinstance(enc_mats_request, dict):
materials = EncryptionMaterials(
encryption_context=enc_mats_request.get("encryption_context", {})
encryption_context=enc_mats_request.get("encryption_context", {}) or {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this is used in multiple places, is it worth having a utility method?

"encryption_context_from_request", {}
),
)
or {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Readability: In my view, this separate line may cause confusion while reading.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Formatting is enforced by ruff. Making this a utility function makes it a moot point anyway.

@rishav-karanjit rishav-karanjit 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.

I agree with Bikram's comments about having a Utlity method to get the EC and it should be totally worth it. I will let Kess decide if its worth it and on priority of doing it.

@kessplas kessplas merged commit 732100e into staging May 7, 2026
6 checks passed
@kessplas kessplas deleted the kessplas/none-guard branch May 7, 2026 19:56
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.

3 participants