Skip to content

fix(teams): accept null optional membership fields - #13541

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix-CLOUD-3QSB-null-membership-fields
Sep 8, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix-CLOUD-3QSB-null-membership-fields

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What does this PR do?

Fixes team membership creation returning HTTP 500 when an optional string is explicitly null in a JSON request. Utopia HTTP accepts null for optional parameters, but the action required non-null strings.

Accept nullable email, userId, phone, url, and name, then normalize them to their existing empty-string defaults. Identity requirements, URL requirements for client invitations, and non-null input validation remain unchanged. This belongs in CE because Cloud uses this handler from appwrite/server-ce.

Test Plan

Tested through the real local CE HTTP API with PostgreSQL and Redis, using PHP 8.5.10 / PHPUnit 12.5.34. No mocks of the handler or database and no unit tests added.

  • New E2E flow creates a member by email with null phone/name/URL, reads back persisted membership and roles, deletes and re-adds the existing user with null email, and verifies missing identities and malformed phone numbers return 400 without changing membership count or roles.
  • Red/green observed: on the original handler the regression fails with HTTP 500 instead of 201; with this patch it passes (1 test, 30 assertions).

Commands run inside the local API container:

php vendor/bin/phpunit tests/e2e/Services/Teams/TeamsCustomServerTest.php --filter testCreateMembershipWithNullOptionals
# PASS: 1 test, 30 assertions

php vendor/bin/phpunit tests/e2e/Services/Teams/TeamsCustomServerTest.php --filter '/::test(?!DeleteUserUpdatesTeamMembershipCount)/'
# PASS: 12 tests, 225 assertions

php vendor/bin/pint --test src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php tests/e2e/Services/Teams/TeamsCustomServerTest.php
# PASS: 2 files

git diff --check
# PASS

Full-suite limitation: the unfiltered TeamsCustomServerTest.php run passed 12 of 13 tests. testDeleteUserUpdatesTeamMembershipCount timed out waiting for the async deletes worker to reduce the team count from 1 to 0. Re-ran that test with the original handler restored and reproduced the same failure. It is not counted as passing. Client invitation/email delivery flows were not run. This is a backend-only change; screenshots are not applicable.

Related PRs and Issues

Checklist

  • Read the contributing guidelines.
  • No API metadata changes; specs and example docs are unchanged.

@greptile-apps

greptile-apps Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates team membership creation to accept explicit null values for optional string fields and normalize them to the existing empty-string defaults.

  • Makes email, userId, phone, url, and name nullable at the action boundary.
  • Adds end-to-end coverage for null optionals, identity validation, malformed phone numbers, persistence, and membership roles.
  • Moves user ID capture ahead of response assertions so cleanup remains possible if a later assertion fails.

Confidence Score: 5/5

The PR appears safe to merge with no outstanding correctness or repository-rule issues.

The previous cleanup finding is fully addressed by saving the created user ID immediately after confirming membership creation, before subsequent assertions can fail; no new issues were introduced by that change.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php Accepts nullable optional membership fields and normalizes them before existing validation and creation logic.
tests/e2e/Services/Teams/TeamsCustomServerTest.php Adds comprehensive regression coverage and now captures the created user ID early enough for reliable cleanup.

Reviews (2): Last reviewed commit: "test(teams): capture created user before..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-CLOUD-3QSB-null-membership-fields (after).

Metric Before After Change
🚀 Requests/sec 238.03 237.09 ⚪ -0.4%
⏱️ Latency P50 73.45 ms 74.62 ms ⚪ +1.6%
⏱️ Latency P95 170.01 ms 168.07 ms ⚪ -1.1%
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 74.62 168.07 14,820 237.09 -1.94
Account 150.68 265.68 780 13.1 +2.83
TablesDB 72.4 127.39 8,060 131.3 +2.18
Storage 68.18 141.31 3,900 65.55 -3.49
Functions 111.95 198.67 2,080 35.67 -6.66

Top API waits (after)

API request Max wait (ms)
account.prefs.update 365.6
account.name.update 364.51
functions.delete 342.65
functions.create 293.73
storage.buckets.create 292.03

@ChiragAgg5k
ChiragAgg5k merged commit 9b748ca into main Sep 8, 2026
46 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix-CLOUD-3QSB-null-membership-fields branch September 8, 2026 14:34
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 tasks
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