Repository navigation
fix: restore BaseMessage.data default, validated - #273
Merged
Merged
Conversation
0.4.0 made data required to stop typed subclasses from silently accepting a
missing payload (pydantic does not validate defaults). validate_default=True
gives the same protection: the {} default fails validation for
BaseMessage[Order] and passes for the untyped base, so
BaseMessage(source=..., type=...) works again.
Contributor
QualOps Code Quality AnalysisStatus: Summary
🟡 Medium Issues (1)
📊 Full ReportPowered by QualOps |
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.
Undoes the breaking part of #259 while keeping its fix.
#259 made
BaseMessage.datarequired because pydantic does not validate defaults, soBaseMessage[Order]accepted an envelope with nodataand handed the handler a plain{}. Pydantic'svalidate_default=Truecovers exactly that case: the{}default is validated against the bound type, fails forBaseMessage[Order](ValidationError, which typed subscriptions already treat as "not ours") and passes for the untyped base.BaseMessage(source, type)no datadata == {}BaseMessage[Order]no dataBaseMessage[Order]wrong shapeMessageis unchanged. New testtest_untyped_base_message_defaults_to_empty_dictfails on main and passes here; the #259 tests for the typed cases still pass.Verification (local, live Redis + Redpanda, Python 3.12): 109 passed, 0 skipped; mypy clean in the CI configuration; ruff clean.