Repository navigation
Conversation
RichText.de_json treated any string that parses to a JSON object as a
serialized RichText. A pre block holding a code sample like {"foo": "bar"}
has no "type" key, so the lookup fell through to None and the block lost its
text. Sending that message back failed with RICH_MESSAGE_CONTENT_REQUIRED.
Only a dict that resolves to a known RichText counts as serialized now, and
anything else keeps the original string. The type dispatch moved into
_from_dict so the string branch can fall back to it.
Fixes eternnoir#2646.
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.
Description
RichText.de_jsontreated any string that parses to a JSON object as a serialized RichText. Apreblock holding a code sample like{"foo": "bar"}has notypekey, so the dispatch fell through toNoneand the block lost its text:Sending that message back then fails with
RICH_MESSAGE_CONTENT_REQUIRED(#2646).Only a dict that resolves to a known RichText counts as serialized now; anything else keeps the original string. The type dispatch moved into
_from_dictso the string branch can fall back to it. The[56]case from #2635 still works, and so do{},{"a": [1, 2]}and{"type": "not_a_richtext"}.Describe your tests
Added
test_json_richtext_plain_json_object_stays_textintests/test_types.py. It covers the preformatted block from the issue plus the other JSON-shaped strings, and asserts a real serialized RichText still deserializes.Full suite:
308 passed, 73 skipped.Python version: 3.12.3
OS: macOS 27.2
Checklist: