Repository navigation
fix(dbt): quote exported YAML scalars so values keep their type - #372
Merged
Merged
Conversation
export_dbt_tests hand-writes schema.yml. _scalar left a string unquoted when it matched ^[A-Za-z0-9_][A-Za-z0-9_.-]*$ and float() rejected it, but YAML 1.1 loaders (PyYAML, used by dbt) still re-type such text: 2024-01-01 loads as a date, 0x1F as 31, 0b101 as 5. The `$` anchor also matched before a trailing newline, so "a\n" was written bare, and the double-quoted branch left newlines raw, so they folded to spaces. Strings are now emitted plain only when they fully match a letter or underscore followed by [A-Za-z0-9_.-] and are not a bool/null/nan/inf word; everything else is double-quoted. Inside quotes, backslash, quote, \n, \t, \r, other C0/C1 controls, DEL, U+2028/U+2029, lone surrogates and U+FFFE/U+FFFF are escaped. Python floats are written so PyYAML reads floats back: .nan/.inf/-.inf, and 1e+16 as 1.0e+16. Genuine ints, floats and bools stay unquoted YAML numbers/bools. Closes #342
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
FreshData benchmark report —
|
| fixture | n_rows | n_cols | p50 s | p95 s | peak MB | repair % | false-repair % | preserve % | trust | monotonic | export % |
|---|
Authored-code reduction (Metric 6)
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
export_dbt_testshand-writesschema.yml, and_scalarleft strings unquoted when they would still change type under YAML 1.1 loaders (PyYAML, which dbt uses):2024-01-01loaded as a date,0x1Fas31,0b101as5. The regex's$anchor also matched before a trailing newline, so"a\n"was written unquoted and lost its newline. Newlines inside quoted scalars were not escaped, so they folded to spaces.[A-Za-z0-9_.-]and is not a bool/null/nan/inf word. Everything else is double-quoted.\n,\t,\r, other C0/C1 controls, DEL, U+2028/U+2029, lone surrogates and U+FFFE/U+FFFF are escaped..nan/.inf/-.inf, and exponent forms get a mantissa dot (1e+16becomes1.0e+16).Tests
New
tests/test_integrations/test_dbt_tests_exporter_yaml.py. Every value is loaded back withyaml.safe_load, both as a mapping value and as a list item, and must come back as the same value and type:12:30,0x1F/0b101/0o17/017,1e3,1_000,.5,+1/-1,.inf/.NaN, yes/No/on/null/~/y/n, YAML indicators, leading/trailing spaces, quotes, backslashes, tabs, newlines, control characters, NEL, U+2028/U+2029, BOM, non-characters, non-ASCII.None, and floats including NaN, ±inf,1e16,1e-5and numpy floats.export_dbt_tests, plus a mixedaccepted_valuesround trip.Verification
ruff check .clean;mypy src/freshdatacleanpytest -m "not online and not large": py3.12 4374 passed; py3.9 4370 passedCloses #342