Skip to content

Fix missing array_values() after array_diff() in VCS PR cleanup - #11742

Closed
zaidxshaikh wants to merge 1 commit into
appwrite:mainfrom
zaidxshaikh:fix-vcs-array-diff-missing-reindex
Closed

zaidxshaikh wants to merge 1 commit into
appwrite:mainfrom
zaidxshaikh:fix-vcs-array-diff-missing-reindex

Conversation

@zaidxshaikh

Copy link
Copy Markdown

Description

Fixes #11741

When a pull request is closed and external contribution cleanup runs in the VCS GitHub events handler, array_diff() is used to remove the PR ID from providerPullRequestIds without wrapping in array_values().

Problem

array_diff() preserves the original numeric keys after removing elements:

$ids = ['101', '102', '103'];
$result = array_diff($ids, ['102']);
// Result: [0 => '101', 2 => '103'] — non-sequential keys

When stored in the database (JSON-encoded), PHP produces a JSON object {"0":"101","2":"103"} instead of a JSON array ["101","103"], causing malformed data storage.

Fix

Wrap array_diff() with array_values() to reindex the array, consistent with the pattern used elsewhere in the codebase:

  • Databases/Workers/Databases.php:368 — \array_values(\array_diff(...))
  • Account/Http/Account/MFA/Challenges/Update.php:150 — \array_values(\array_diff(...))

array_diff() preserves original keys after removing elements, producing
non-sequential numeric keys. Without array_values(), PHP JSON-encodes
the result as an object instead of an array, causing malformed data
storage in providerPullRequestIds.
@greptile-apps

greptile-apps Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a subtle but real data-integrity bug in the VCS GitHub events handler where array_diff() without array_values() caused removed PR IDs to leave behind non-sequential numeric keys. When PHP JSON-encodes an array with non-sequential keys it produces a JSON object (e.g. {"0":"101","2":"103"}) rather than a JSON array (["101","103"]), which corrupts the providerPullRequestIds field stored in the database.

  • Root cause: array_diff() preserves original array keys; wrapping with array_values() re-indexes the result to produce a proper sequential array.
  • Fix: Line 237 now reads \\array_values(\\array_diff($providerPullRequestIds, [$providerPullRequestId])), matching the identical pattern already used in Databases/Workers/Databases.php and Account/Http/Account/MFA/Challenges/Update.php.
  • The change is minimal, correct, and consistent with the established codebase convention.

Confidence Score: 5/5

Safe to merge — single-line bug fix with no side effects and consistent with existing codebase patterns.

The change is a minimal, well-understood PHP correctness fix with no ambiguity. It resolves a confirmed data-integrity issue (malformed JSON stored in the database), follows the established \array_values(\array_diff(...)) convention used elsewhere in the repo, and introduces no new logic or risk. No P0 or P1 issues remain.

No files require special attention.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php Wraps array_diff() with array_values() to reindex keys after PR ID removal, preventing JSON object serialization when storing providerPullRequestIds.

Reviews (1): Last reviewed commit: "Fix missing array_values() after array_d..." | Re-trigger Greptile

@HarshMN2345

Copy link
Copy Markdown
Member

Closing as this has already been addressed by #13530. Thanks!

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.

Missing array_values() after array_diff() in VCS GitHub PR cleanup causes malformed array storage

2 participants