Skip to content

fix(messaging): treat explicit nulls as omitted in push message create - #13849

Closed
ChiragAgg5k wants to merge 1 commit into
mainfrom
fix/push-create-null-params
Closed

ChiragAgg5k wants to merge 1 commit into
mainfrom
fix/push-create-null-params

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What does this PR do?

POST /v1/messaging/messages/push returns a 500 when a client sends an explicit null for any optional param. This is happening in production (about 130 events since 5 Sep, all with image: null).

utopia-php/http skips validation for an optional param whose value is null, and it passes that null to the action instead of the param default. Push\Create::action() declared most optional params as non-nullable (string $image, int $badge, bool $draft, …), so PHP threw a TypeError. topics/users/targets were already ?array, but a null there reached \count() and threw as well.

The fix makes the optional scalars nullable and restores the declared defaults with ??= where the action depends on the value (arrays, badge, booleans, priority). The string params were already only checked with !empty(). An explicit null now behaves the same as leaving the param out, which matches Push\Update and the fix already on main in Executions\Create ($path ??= '/').

Before

POST /v1/messaging/messages/push
Content-Type: application/json

{"messageId":"unique()","title":"Hello","body":"World","image":null,"draft":true}
HTTP 500
{"message":"Server Error","code":500,"type":"general_unknown","version":"2.2.0"}
TypeError: Appwrite\Platform\Modules\Messaging\Http\Messages\Push\Create::action(): Argument #9 ($image) must be of type string, null given
POST /v1/messaging/messages/push
Content-Type: application/json

{"messageId":"unique()","title":"Hello","topics":null,"users":null,"targets":null}
HTTP 500
{"message":"Server Error","code":500,"type":"general_unknown","version":"2.2.0"}
TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given  (Push/Create.php:150)

After

HTTP 201
{
  "$id": "6ab396a15680f5c68706",
  "providerType": "push",
  "topics": [],
  "users": [],
  "targets": [],
  "scheduledAt": null,
  "deliveredAt": null,
  "deliveryErrors": [],
  "deliveredTotal": 0,
  "data": {"title": "Hello", "body": "World", "priority": "high"},
  "status": "draft"
}
HTTP 400
{"message":"Message with the requested ID has no recipients (topics or users or targets).","code":400,"type":"message_missing_target","version":"2.2.0"}

All responses were captured against a local stack. Dev-mode file/trace fields are left out.

Test Plan

  • New e2e test testCreatePushWithNullOptionalParams sends every optional param as null. It checks for a 201 and reads the message back to confirm the stored recipients are empty arrays and the stored data holds only title, body and the default priority. It then sends null recipients without draft and expects a 400 message_missing_target.
  • Watched the test fail on the unfixed code (Failed asserting that 500 is identical to 201) and pass with the fix.
  • MessagingCustomServerTest and MessagingConsoleClientTest: 47 tests each, all passing (8 skipped).
  • pint --test passes on the changed files.

Related PRs and Issues

None.

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

Optional params skip validation when null, so an explicit null bypassed the param default and reached the action, crashing on the non-nullable signature or on count(null) with a 500.
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The production fix appears behaviorally safe, but the implementation-coupled regression assertion must be replaced to satisfy the repository’s explicit testing requirement.

Fix All in Claude CodeFindings

  1. P2 Test Mirrors Implementation Default ▶
Fix with agent prompt
### Issue 1
tests/e2e/Services/Messaging/MessagingBase.php:2272-2276
The exact `priority => high` assertion copies the route default and the action fallback instead of proving that explicit `null` behaves like omission. This violates the repository directive not to mirror source configuration in tests and makes the test brittle if the default legitimately changes. Compare the observable result of an explicit-null request with an omitted-parameters baseline instead. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR prevents explicit null values for optional push-message parameters from causing type and count() failures by accepting nullable inputs and restoring defaults before validation and persistence.

  • Normalizes nullable recipient arrays, badge, boolean flags, and priority.
  • Allows nullable optional strings whose existing guards already treat null like omission.
  • Adds end-to-end coverage for successful draft creation and missing-recipient rejection.

Reviews (1) · Last reviewed commit: "fix(messaging): treat explicit nulls as ..."

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/push-create-null-params (after).

Metric Before After Change
🚀 Requests/sec 204.91 208.77 ⚪ +1.9%
⏱️ Latency P50 86.25 ms 82.49 ms ⚪ -4.4%
⏱️ Latency P95 191.14 ms 192.67 ms ⚪ +0.8%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 82.49 192.67 13,110 208.77 +1.52
Account 157.54 291.25 690 11.44 -1.47
TablesDB 78.51 145.38 7,130 116.57 -10.43
Storage 79.16 167.27 3,450 57.91 +5.18
Functions 121.71 240.06 1,840 31.52 +17.95

Top API waits (after)

API request Max wait (ms)
account.prefs.update 493.57
account.name.update 448
functions.create 429.37
functions.variables.update 404.52
functions.variables.create 399.37

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

Superseded by #13852, which fixes this at the framework level (utopia-php/monorepo#327) instead of patching push message create alone.

@ChiragAgg5k
ChiragAgg5k deleted the fix/push-create-null-params branch September 23, 2026 14:26
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