Skip to content

Avoid mutating passed-in request data - #982

Merged
LeMyst merged 3 commits into
masterfrom
avoid-mutating-data
Sep 19, 2026
Merged

LeMyst merged 3 commits into
masterfrom
avoid-mutating-data

Conversation

@LeMyst

@LeMyst LeMyst commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Convert and copy incoming request payloads to prevent accidental mutation of caller-provided mappings. In mediawiki_api_call, kwargs['data'] is wrapped with dict(...) so updates (like adding format) work for non-dict mappings and don't modify the original. In mediawiki_api_call_helper, data is shallow-copied before use to avoid side effects when modifying the payload. This makes API helper functions safer when callers pass in shared or immutable mapping types.

Convert and copy incoming request payloads to prevent accidental mutation of caller-provided mappings. In mediawiki_api_call, kwargs['data'] is wrapped with dict(...) so updates (like adding format) work for non-dict mappings and don't modify the original. In mediawiki_api_call_helper, data is shallow-copied before use to avoid side effects when modifying the payload. This makes API helper functions safer when callers pass in shared or immutable mapping types.
@LeMyst
LeMyst force-pushed the avoid-mutating-data branch from 36b32a5 to 52a104b Compare July 3, 2026 21:20
LeMyst and others added 2 commits September 19, 2026 14:58
data.copy() crashed when data was None (a case the helper explicitly
handles) and when data was a Mapping without a copy() method. Use
dict(data) instead, guarded against None.

Add tests checking that mediawiki_api_call and mediawiki_api_call_helper
leave the caller's payload untouched, accept a read-only mapping, and
still accept data=None.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@LeMyst
LeMyst merged commit f4e3879 into master Sep 19, 2026
15 checks passed
@LeMyst
LeMyst deleted the avoid-mutating-data branch September 19, 2026 13:01
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