Skip to content

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

Merged
Decipher merged 0 commit into
8.x-1.xfrom
feature/3569210-postgres-target-id
Aug 27, 2026
Merged

fix(#3569210): compare target_id numerically so retroactive update works on PostgreSQL#19
Decipher merged 0 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

Two commits, so the community fix keeps its own author:

  1. fix: #3569210 Do not treat target_id as text by Mykola Podpriatov (nickolaj), taken from the head of drupal.org MR !59 where liam morland re-rolled it.
  2. test(#3569210): pin empty-field exclusion, adding the kernel test and an explanatory comment. No functional change.

The fix itself is the one-line numeric comparison:

->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.

That PostgreSQL run was made before this branch was rebased onto the merged cross-scheme work. The condition it targets is unchanged by that merge and still sits at src/Batch/Updater.php:59, and the suite is green on the rebased branch, but note that CI here runs MySQL and SQLite only, so no automated job can fail on this bug.

BatchUpdaterTest::testReturnsFalseWhenFileFieldIsEmpty pins the exclusion semantics of the numeric operator. It is coverage of the intent rather than a regression test, since the string comparison is legal on the databases CI runs.

Notes

The cross-scheme move work in #18 (https://www.drupal.org/i/3419618) has since merged, and this branch is rebased on top of it.

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

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 350bf86e-b10b-4968-a864-ae559c5dabee

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: 4fb64390-44dd-4d91-a72b-7dacc549409b

📥 Commits

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

📒 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 d23f4

The PR applies a localized database-compatibility fix and reports passing verification; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
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 and concisely describes the main change: using a numeric comparison for target_id to fix retroactive updates on PostgreSQL.
✨ 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 (91ee7da) to head (d23f47e).

Additional details and impacted files
@@           Coverage Diff            @@
##           8.x-1.x      #19   +/-   ##
========================================
  Coverage    83.39%   83.39%           
========================================
  Files           20       20           
  Lines          783      783           
========================================
  Hits           653      653           
  Misses         130      130           

☔ 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.

@Decipher
Decipher force-pushed the feature/3569210-postgres-target-id branch from f16dc76 to d23f47e Compare August 27, 2026 00:43
@Decipher

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

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 merged commit d23f47e into 8.x-1.x Aug 27, 2026
10 checks passed
@Decipher
Decipher deleted the feature/3569210-postgres-target-id branch August 27, 2026 03:18
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