Skip to content

fix: normalize line endings in FileHash to prevent false state:modified results#12731

Open
claygeo wants to merge 2 commits into
dbt-labs:main_backupfrom
claygeo:fix/normalize-line-endings-state-comparison
Open

fix: normalize line endings in FileHash to prevent false state:modified results#12731
claygeo wants to merge 2 commits into
dbt-labs:main_backupfrom
claygeo:fix/normalize-line-endings-state-comparison

Conversation

@claygeo
Copy link
Copy Markdown
Contributor

@claygeo claygeo commented Mar 29, 2026

Problem

Fixes #11473

When comparing manifests built on different platforms (e.g. local Windows CLI vs dbt Cloud on Linux), dbt ls --select state:modified selects ALL files even when nothing changed. This happens because Windows uses CRLF line endings while Linux uses LF, producing different SHA-256 hashes for identical logical content.

This affects every dbt Cloud user who develops locally on Windows and uses state comparisons. The current workaround is disabling git line ending conversion, which is a footgun.

Fix

Normalize line endings to LF (\n) before hashing in FileHash.from_contents(). The normalization replaces both \r\n (Windows) and standalone \r (legacy Mac) with \n before encoding to UTF-8 and hashing.

This ensures the same logical file content produces the same checksum regardless of the platform it was created on.

Note: This is a one-way change. Existing checksums in manifests built on Linux (LF only) will not change since \n is already the normalized form. Checksums in manifests built on Windows will change on the next build, which is the correct behavior (they should have matched the Linux checksums all along).

5 lines changed in 1 file.

@claygeo claygeo requested a review from a team as a code owner March 29, 2026 03:17
@cla-bot cla-bot Bot added the cla:yes label Mar 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@github-actions
Copy link
Copy Markdown
Contributor

Additional Artifact Review Required

Changes to artifact directory files requires at least 2 approvals from core team members.

@github-actions github-actions Bot added the community This PR is from a community member label Mar 29, 2026
claygeo added a commit to claygeo/dbt-core that referenced this pull request Mar 30, 2026
@claygeo claygeo force-pushed the fix/normalize-line-endings-state-comparison branch from a899b17 to da1b8f7 Compare March 30, 2026 15:28
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.43%. Comparing base (34d41ec) to head (da1b8f7).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12731      +/-   ##
==========================================
- Coverage   91.44%   91.43%   -0.02%     
==========================================
  Files         203      203              
  Lines       25803    25804       +1     
==========================================
- Hits        23596    23594       -2     
- Misses       2207     2210       +3     
Flag Coverage Δ
integration 88.33% <100.00%> (-0.01%) ⬇️
unit 65.50% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 65.50% <100.00%> (+<0.01%) ⬆️
Integration Tests 88.33% <100.00%> (-0.01%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

claygeo added a commit to claygeo/dbt-core that referenced this pull request Mar 30, 2026
@claygeo claygeo force-pushed the fix/normalize-line-endings-state-comparison branch from da1b8f7 to c54c98d Compare March 30, 2026 17:29
claygeo added a commit to claygeo/dbt-core that referenced this pull request Mar 30, 2026
@claygeo claygeo force-pushed the fix/normalize-line-endings-state-comparison branch from c54c98d to 0c27292 Compare March 30, 2026 18:29
claygeo added a commit to claygeo/dbt-core that referenced this pull request Mar 30, 2026
@claygeo claygeo force-pushed the fix/normalize-line-endings-state-comparison branch from 0c27292 to 1a51321 Compare March 30, 2026 18:38
claygeo added 2 commits April 1, 2026 11:21
…ed results

When comparing manifests built on different platforms (e.g. local
Windows vs dbt Cloud Linux), files with identical logical content
produce different hashes because CRLF vs LF line endings change the
hash input. This causes dbt ls --select state:modified to select ALL
files even when nothing actually changed.

Normalize line endings to LF before hashing in FileHash.from_contents.
This ensures the same logical file content produces the same checksum
regardless of the platform it was created on.

Fixes dbt-labs#11473
@claygeo claygeo force-pushed the fix/normalize-line-endings-state-comparison branch from 1a51321 to 07d7459 Compare April 1, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla:yes community This PR is from a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Ignore line endings in state comparison

1 participant