Skip to content

acc: make update_file.py replace bytes to preserve line endings - #6944

Merged
Sankalp-Mittal merged 2 commits into
mainfrom
sankalp-mittal/update-file-binary
Oct 6, 2026
Merged

Sankalp-Mittal merged 2 commits into
mainfrom
sankalp-mittal/update-file-binary

Conversation

@Sankalp-Mittal

Copy link
Copy Markdown
Contributor

Changes

acceptance/bin/update_file.py now reads and writes the file as bytes, so only the matched bytes change. If the file already uses CRLF, \n in OLD/NEW is converted to \r\n so multi-line replacements still match.

Why

Text mode on Windows reads CRLF as LF and writes every LF back as CRLF. An LF file (*.txt is pinned to eol=lf in acceptance/.gitattributes, and files written by printf/envsubst are LF) came back with CRLF after any edit. That changes the file's hash and upload payload beyond the intended edit. bundle/resources/job_runs/on_file_change_glob already works around this with printf instead of update_file.py.

Windows runners check out with core.autocrlf=true, so checked-in databricks.yml files are CRLF there. About 10 scripts pass multi-line OLD strings (e.g. clusters/libraries-update, job_runs/on_file_change, migrate/auto/clean). These used to match through text mode's newline translation, and the CRLF conversion keeps them matching.

Tests

  • Checked by hand: LF and CRLF files with a multi-line replacement each keep their original line endings, and a missing OLD still exits non-zero with the file contents.
  • These acceptance tests pass locally with unchanged output: migrate/auto/clean, migrate/auto/direct-only, clusters/libraries-update, clusters/deploy/update-and-resize-autoscale, job_runs/on_file_change, job_runs/on_bundle_deploy, pipelines/destroy/destroy-pipeline-cascade, resource_deps/immutable_field_ref, postgres_branches/update_expire_time.

This pull request and its description were written by Isaac.

update_file.py opened the file in text mode. On Windows that reads CRLF as
LF and writes every LF back as CRLF, so an LF file (e.g. *.txt, which
.gitattributes pins to eol=lf, or files written by printf/envsubst) came
back with CRLF line endings. That changes the file's hash and upload
payload beyond the intended edit.

Read and write bytes instead. When the file already uses CRLF, convert
"\n" in OLD/NEW to "\r\n" so multi-line replacements keep matching on
Windows checkouts with core.autocrlf=true.

Co-authored-by: Isaac <no-reply@databricks.com>
@Sankalp-Mittal
Sankalp-Mittal requested a review from a team as a code owner October 6, 2026 11:42
@Sankalp-Mittal
Sankalp-Mittal requested a review from rclarey October 6, 2026 11:42
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: f354421

Run: 37467464112

Env 🔄​flaky ✅​pass 🙈​skip Time
✅​ aws linux 276 16 9:31
✅​ aws windows 278 14 5:44
✅​ azure linux 275 16 9:01
✅​ azure windows 277 14 5:49
✅​ gcp linux 276 16 8:36
🔄​ gcp windows 1 277 14 7:30
Test Name gcp windows
🔄​ TestAccept 🔄​f
Top 6 slowest tests (at least 2 minutes):
duration env testname
4:00 aws linux TestAccept
3:56 azure linux TestAccept
3:53 gcp linux TestAccept
3:46 azure windows TestAccept
3:10 aws windows TestAccept
2:53 gcp windows TestAccept

Comment thread acceptance/bin/update_file.py Resolved
On a CRLF file, "\n" in OLD/NEW was converted to "\r\n" unconditionally,
so an argument that already had "\r\n" became "\r\r\n". Normalize to "\n"
first, then convert.

Co-authored-by: Isaac <no-reply@databricks.com>
@Sankalp-Mittal
Sankalp-Mittal added this pull request to the merge queue Oct 6, 2026
Merged via the queue into main with commit cda4a87 Oct 6, 2026
25 checks passed
@Sankalp-Mittal
Sankalp-Mittal deleted the sankalp-mittal/update-file-binary branch October 6, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants