Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def _normalize_raw(raw: Any) -> Any:
raw = {**raw, "enabled": False}
elif raw.get("enabled") is True and raw.get("config") is None:
raw = {**raw, "config": {}}
elif raw.get("enabled") is False:
# When the moderation is disabled, the client may still send
# leftover 'type' / 'config' fields (e.g. {"enabled": false, "type": "", "config": {}}).
# Strip them so the discriminator-tagged union in
# SensitiveWordAvoidanceDisabledConfig (extra="forbid") does not reject the payload.
raw = {key: value for key, value in raw.items() if key in {"enabled"}}
return raw


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def test_validate_raises_when_not_dict(self):
{"sensitive_word_avoidance": {"enabled": False}},
{"sensitive_word_avoidance": {"enabled": None}},
{"sensitive_word_avoidance": {}},
# Regression for issue #38327: client sends leftover type/config fields
# alongside enabled=False. The normalize step must strip them so the
# discriminator-tagged union (extra="forbid") does not reject the payload.
{"sensitive_word_avoidance": {"enabled": False, "type": "", "config": {}}},
{"sensitive_word_avoidance": {"enabled": False, "type": "keywords", "config": {"k": "v"}}},
],
)
def test_validate_disables_when_enabled_false_or_missing(self, config):
Expand Down
Loading