Fix kafka plugin converting characters to Unicode escape sequences (CMEM-8068) - #197
Merged
Merged
Conversation
json.dumps() defaults to ensure_ascii=True, which escaped non-ASCII characters (e.g. ö, ü) into unicode escape sequences in three places: - get_message_with_json_wrapper(): consumed Kafka messages aggregated into the output JSON dataset file - KafkaJSONDataHandler._split_data(): JSON dataset content re-serialized into a produced Kafka message value - KafkaEntitiesDataHandler._split_data(): entity values serialized into a produced Kafka message value All three move original user content into a new artifact (a dataset file or a Kafka message payload), so the escaping changed the representation of that content even though it stayed valid JSON.
Coverage Report
|
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.
Summary
json.dumps()defaults toensure_ascii=True, which silently escaped non-ASCII characters (e.g.ö,ü) into\uXXXXsequences in three places:get_message_with_json_wrapper()— consumed Kafka messages aggregated into the output JSON dataset file (Consumer flow, JSON dataset target)KafkaJSONDataHandler._split_data()— JSON dataset content re-serialized into a produced Kafka message value (Producer flow, JSON dataset source)KafkaEntitiesDataHandler._split_data()— entity values serialized into a produced Kafka message value (Producer flow, entities source)ensure_ascii=Falseto all three so the JSON representation of the original content is preserved.All three move original user content into a new artifact (a dataset file or a Kafka message payload) — the escaping kept the JSON technically valid, but changed the textual representation of that content, which is exactly what CMEM-8068 reports.
Test plan
_split_data()/get_message_with_json_wrapper()directly (no Kafka broker or CMEM connection needed, since these are pure in-memory transforms); confirmed each fails against the pre-fix code with the exactö/üpattern, then passes with the fix.ruff checkandmypy(package + tests) pass.pytestrun: all tests that don't require a live CMEM connection pass; the CMEM-gated integration tests error with a pre-existing, unrelated 401 from this environment's local DataIntegration instance.