fix: ignore unrequested row/document types in status counters#193
Conversation
getStatusCounters() seeds a status bucket only for requested resource types and guards the non-row branch with isset(). The row/document branch had no such guard: a row/document count aggregated into the cache for a type that was not requested would auto-vivify $status[$type], read an unseeded 'pending' key (emitting an "Undefined array key" warning) and leave a phantom, non-empty entry that survives the empty-bucket prune. Downstream this surfaced as a flaky assertEmpty($statusCounters) after an otherwise clean migration. Add the same isset() guard the non-row branch already uses so unrequested row/document counts are ignored. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a consistency bug in Transfer::getStatusCounters() where aggregated row/document status counts present in the cache could incorrectly “auto-vivify” counters for unrequested resource types, leading to undefined-array-key warnings and phantom non-empty statusCounters.
Changes:
- Add an
isset($status[$resourceType])guard for the row/document aggregated-count branch to ignore unrequested types (matching the existing guard for non-row resources). - Add a unit test that reproduces the scenario by injecting a row status count into the cache without requesting row migration and asserting the counters remain empty.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Migration/Transfer.php |
Adds a guard to ignore aggregated row/document cache entries when the resource type wasn’t requested, preventing undefined key warnings and phantom counters. |
tests/Migration/Unit/General/TransferTest.php |
Adds a regression test ensuring unrequested row counts in the cache are ignored by getStatusCounters(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Greptile SummaryThis PR fixes a bug in
Confidence Score: 5/5Safe to merge — the change is a minimal, targeted guard with no impact on requested resource types. The fix is a single-line guard that exactly mirrors the pre-existing pattern used in the adjacent non-row branch. The new test directly exercises the bug-triggering code path (via Cache::add(), which stores Row objects as string counters) and asserts the correct outcome. No existing behaviour for requested resource types is affected. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "fix: ignore unrequested row/document typ..." | Re-trigger Greptile |
Problem
Transfer::getStatusCounters()seeds a status bucket only for requested resource types, and the non-row branch correctly guards withif (isset($status[$resource->getName()]))so it ignores resource types that weren't requested.The row/document branch had no such guard. Row and document counts are aggregated into the cache by status (
cache['row'][$status] = "count"), and that cache can contain a row/document entry for a type that was not part of the migration request (e.g. a stray/skipped document the destination still tallied). When that happens, the branch:$status[$resourceType][$k],$status[$resourceType]['pending']on a bucket that was never seeded →Undefined array key "pending"warning, andThe result is a non-empty
statusCountersafter an otherwise clean migration. Downstream (Appwrite server-ce / cloud) this surfaced as a flakyassertEmpty($statusCounters)in the Appwrite→Appwrite migration e2e test, failing intermittently across unrelated PRs.Fix
Add the same
isset($status[$resourceType])guard the non-row branch already uses, so unrequested row/document counts are ignored consistently. No behaviour change for requested row/document types.Test
TransferTest::testStatusCountersIgnoreUnrequestedRowCountsadds a row count to the cache for a type that was not requested and assertsgetStatusCounters()ignores it and returns[].Failed asserting that an array does not have the key 'row'plus theUndefined array key "pending"warning.Verified locally: full Unit suite green,
composer lint(Pint) clean, PHPStan clean on the changed files.🤖 Generated with Claude Code