Repository navigation
Escape non-ASCII characters in tojson like Python's json.dumps - #16908
Open
yashaggarwal85d wants to merge 2 commits into
Open
yashaggarwal85d wants to merge 2 commits into
yashaggarwal85d wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
Resolves #16830
Problem
tojsonwrites non-ASCII characters as raw UTF-8, but dbt 1.x usesjson.dumpswith its defaultensure_ascii=True, which writes\uXXXX. Solocal_md5(tojson(...))gives a different hash on v2 for anything with non-ASCII text, which is what makes Elementary re-insert its artifacts every time you switch engines.Solution
Added
write_string_fragmenttoPythonStyleFormatterso it escapes everything outside printable ASCII the way Python does: lowercase\uXXXX, surrogate pairs above U+FFFF, and DEL (0x7f) too, since Python escapes that one as well. Same idea asPythonJsonFormatterin dbt-state. Added a test withあ,é, an emoji, U+2028 and DEL, plus thelocal_md5hash from the issue (f3dd52a0cdda6cf470609dcfc4759191), all checked againstjson.dumpsin Python.Checklist
This fix was AI-assisted and reviewed by me. Thanks