Skip to content

fix(clickhouse): use isset() instead of array_key_exists() for Log object in createBatch#123

Merged
lohanidamodar merged 1 commit into
mainfrom
fix/createbatch-array-key-exists-log-object
May 20, 2026
Merged

fix(clickhouse): use isset() instead of array_key_exists() for Log object in createBatch#123
lohanidamodar merged 1 commit into
mainfrom
fix/createbatch-array-key-exists-log-object

Conversation

@lohanidamodar
Copy link
Copy Markdown
Contributor

Summary

The legacy-translation block added in #122 (2.4.0) calls \array_key_exists($legacy, $log) on each $log in the batch. When callers pass Utopia\Audit\Log (an ArrayAccess subclass of Document) — as Appwrite Cloud's Activity worker does via getClickHouseAdapter()->createBatch([new Log(...), ...]) — PHP 8 throws:

TypeError: array_key_exists(): Argument #2 ($array) must be of type array, Utopia\Audit\Log given

The whole batch insert then fails (caught silently downstream), so no rows land in ClickHouse.

isset($log[$key]) does the same intent here (only false for absent or null values, and null userId/userType/userInternalId is never meaningful in this code path) and works for both plain arrays and ArrayAccess objects.

Test plan

  • Existing unit tests pass
  • Verified locally that createBatch([new Log(['actorId' => '...', 'actorType' => '...', ...])]) no longer throws TypeError
  • Appwrite Cloud Activities E2E (downstream consumer) now writes rows successfully

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 20, 2026

Greptile Summary

This PR fixes a TypeError in ClickHouse::createBatch() introduced by the legacy-key translation block in #122: array_key_exists() throws when its second argument is an ArrayAccess object rather than a plain array, which breaks batch inserts when callers pass Log instances. The one-line change to isset() resolves this for both plain arrays and ArrayAccess objects.

  • Replaces array_key_exists($legacy, $log) / !array_key_exists($current, $log) with isset($log[$legacy]) / !isset($log[$current]) on line 1688, directly fixing the TypeError.
  • The adjacent $logData block (line 1698) is correctly left unchanged because $logData is always a plain PHP array extracted via $log['data'] ?? [].

Confidence Score: 5/5

Safe to merge — the change is a single-line, targeted fix that eliminates the TypeError without altering any other logic.

The change is minimal and correct. isset() works for both plain arrays and ArrayAccess objects, resolving the TypeError while preserving the intent of skipping null legacy values (explicitly called out as acceptable in the PR description). The $logData block correctly retains array_key_exists since it operates on a guaranteed plain PHP array.

No files require special attention.

Important Files Changed

Filename Overview
src/Audit/Adapter/ClickHouse.php Replaces array_key_exists($legacy, $log) with isset($log[$legacy]) in the legacy-key translation loop so the code works for both plain arrays and ArrayAccess objects (e.g. Utopia\Audit\Log), fixing a TypeError on PHP 8. The nearby $logData check (line 1698) correctly retains array_key_exists since $logData is always a plain PHP array.

Reviews (1): Last reviewed commit: "fix(clickhouse): use isset() instead of ..." | Re-trigger Greptile

@lohanidamodar lohanidamodar requested a review from ChiragAgg5k May 20, 2026 06:10
@lohanidamodar lohanidamodar merged commit eddd79d into main May 20, 2026
4 checks passed
@lohanidamodar lohanidamodar deleted the fix/createbatch-array-key-exists-log-object branch May 20, 2026 06:25
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.

2 participants