Skip to content

fix(#3569210): compare target_id numerically so retroactive update works on PostgreSQL - #19

Open
Decipher wants to merge 1 commit into
8.x-1.xfrom
feature/3569210-postgres-target-id
Open

fix(#3569210): compare target_id numerically so retroactive update works on PostgreSQL#19
Decipher wants to merge 1 commit into
8.x-1.xfrom
feature/3569210-postgres-target-id

Conversation

@Decipher

@Decipher Decipher commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Fixes https://www.drupal.org/project/filefield_paths/issues/3569210

Problem

Batch\Updater::batchUpdate() builds the retroactive update entity query with a string comparison on the file reference column:

->condition($field_config->getName() . '.target_id', '', '<>')

target_id is a bigint. MySQL and SQLite silently coerce the empty string, but PostgreSQL rejects the comparison, so every retroactive update on a PostgreSQL site crashes before the batch is created:

DatabaseExceptionWrapper: SQLSTATE[22P02]: Invalid text representation: 7
ERROR: invalid input syntax for type bigint: ""

Fix

Adopts the one-line numeric comparison from the community fix on drupal.org MR !59 (nickolaj, re-rolled by liam morland):

->condition($field_config->getName() . '.target_id', 0, '>')

Semantics are identical on every supported database: target_id is a file entity ID, always a positive integer when set, and rows with no value are absent from the field table entirely.

Verification

Reproduced and verified against a local PostgreSQL 16:

  • Before: SIMPLETEST_DB="pgsql://..." make test-kernel fails with 7 errors, all SQLSTATE[22P02] raised from Updater.php by the existing kernel tests.
  • After: full kernel suite green on PostgreSQL (96 tests, 1 unrelated version skip) and unchanged on SQLite.
  • New BatchUpdaterTest::testReturnsFalseWhenFileFieldIsEmpty pins the exclusion semantics of the numeric operator.

Notes

Independent of #18, both branch directly off 8.x-1.x to mirror how the drupal.org MRs must be structured. The two touch the same file, so whichever merges second takes a trivial rebase of the same line.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved batch updates for records with empty file fields.
    • Prevented PostgreSQL errors caused by comparing numeric values with empty strings.
  • Tests
    • Added coverage to verify batch updates correctly return no result when a file field is empty.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8df375dc-ea9a-4fbe-bb2c-d95684dd7ada

📥 Commits

Reviewing files that changed from the base of the PR and between 9f56e80 and f16dc76.

📒 Files selected for processing (2)
  • src/Batch/Updater.php
  • tests/src/Kernel/BatchUpdaterTest.php

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The batch updater now compares target_id numerically. A kernel test covers entities with empty file fields and verifies that no batch is created.

Changes

Batch updater query fix

Layer / File(s) Summary
Numeric target filtering and regression coverage
src/Batch/Updater.php, tests/src/Kernel/BatchUpdaterTest.php
The batch query now selects records with target_id > 0. The kernel test verifies that an empty file field returns no batch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to f16dc

This localized database comparison fix is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main PostgreSQL fix: changing the target_id comparison to a numeric condition for retroactive updates.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/3569210-postgres-target-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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Decipher
Decipher force-pushed the feature/3569210-postgres-target-id branch from 8c16914 to f16dc76 Compare August 19, 2026 06:54
@Decipher
Decipher changed the base branch from feature/3419618-cross-scheme-move to 8.x-1.x August 19, 2026 06:54
@Decipher

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Decipher Decipher closed this Aug 19, 2026
@Decipher Decipher reopened this Aug 19, 2026
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.39%. Comparing base (74954f3) to head (f16dc76).
⚠️ Report is 2 commits behind head on 8.x-1.x.

Additional details and impacted files
@@             Coverage Diff             @@
##           8.x-1.x      #19      +/-   ##
===========================================
+ Coverage    81.16%   83.39%   +2.23%     
===========================================
  Files           19       20       +1     
  Lines          722      783      +61     
===========================================
+ Hits           586      653      +67     
+ Misses         136      130       -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant