fix: allow users to update phone number to empty without causing dupl…#11521
fix: allow users to update phone number to empty without causing dupl…#11521
Conversation
📝 WalkthroughWalkthroughThis pull request addresses a database constraint issue with phone number uniqueness by normalizing empty phone values to Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
Greptile SummaryThis PR fixes a duplicate-key constraint error that occurred when multiple users attempted to clear their phone number, by storing
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[PATCH /v1/users/:userId/phone] --> B{number == ''}
B -- Yes --> C[phoneValue = null]
B -- No --> D[phoneValue = number]
C --> E[setAttribute phone=null, phoneVerification=false]
D --> E
E --> F{number == ''}
F -- No --> G[Check targets for duplicate identifier\nthrow if exists]
F -- Yes --> H[Skip duplicate check]
G --> I[updateDocument phone=null/number]
H --> I
I --> J[Find oldTarget by oldPhone]
J --> K{oldTarget exists?}
K -- Yes --> L{number == ''}
L -- Yes --> M[deleteDocument oldTarget]
L -- No --> N[updateDocument oldTarget.identifier=number]
K -- No --> O{number == ''}
O -- No --> P[createDocument new target]
O -- Yes --> Q[No-op]
M --> R[purgeCachedDocument]
N --> R
P --> R
Q --> R
R --> S[Return updated user]
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/e2e/Services/Users/UsersBase.php (1)
1651-1701: LGTM - Well-structured test for the duplicate phone fix.The test correctly validates the fix for issue
#11482by:
- Creating two users with distinct valid phone numbers
- Updating both to empty (which would fail with 409 duplicate error before the fix)
- Verifying both updates succeed and GET confirms empty phones
Consider adding cleanup of the created test users to avoid test data accumulation, similar to
testDeleteUser()pattern.♻️ Optional: Add cleanup for test users
$this->assertEmpty($get1['body']['phone'] ?? ''); $this->assertEmpty($get2['body']['phone'] ?? ''); + + // Cleanup test users + $this->client->call(Client::METHOD_DELETE, '/users/' . $user1['body']['$id'], $headers); + $this->client->call(Client::METHOD_DELETE, '/users/' . $user2['body']['$id'], $headers); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/e2e/Services/Users/UsersBase.php` around lines 1651 - 1701, Add cleanup to remove the two users created in testUpdateTwoUsersPhoneToEmpty so test data doesn't accumulate: after the GET verifications call the same delete flow used in testDeleteUser() to remove $user1['body']['$id'] and $user2['body']['$id'] (use Client::METHOD_DELETE with the same $headers and assert 204/expected status), or move creation into a tearDown that deletes those IDs; ensure you reference the testUpdateTwoUsersPhoneToEmpty-created IDs ($user1['body']['$id'] and $user2['body']['$id']) and mirror the assertions/pattern used in testDeleteUser().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/e2e/Services/Users/UsersBase.php`:
- Around line 1651-1701: Add cleanup to remove the two users created in
testUpdateTwoUsersPhoneToEmpty so test data doesn't accumulate: after the GET
verifications call the same delete flow used in testDeleteUser() to remove
$user1['body']['$id'] and $user2['body']['$id'] (use Client::METHOD_DELETE with
the same $headers and assert 204/expected status), or move creation into a
tearDown that deletes those IDs; ensure you reference the
testUpdateTwoUsersPhoneToEmpty-created IDs ($user1['body']['$id'] and
$user2['body']['$id']) and mirror the assertions/pattern used in
testDeleteUser().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b654c164-b524-449b-a5a5-04299ba014f2
📒 Files selected for processing (2)
app/controllers/api/users.phptests/e2e/Services/Users/UsersBase.php
🔄 PHP-Retry SummaryFlaky tests detected across commits: Commit
|
| Test | Retries | Total Time | Details |
|---|---|---|---|
UsageTest::testDatabaseStatsCollectionsAPI |
1 | 10.29s | Logs |
TablesDBConsoleClientTest::testSpatialRelationshipOneToMany |
1 | 240.56s | Logs |
TablesDBCustomClientTest::testUpsertDocument |
1 | 240.53s | Logs |
TablesDBCustomClientTest::testSpatialRelationshipManyToOne |
1 | 240.54s | Logs |
TablesDBCustomServerTest::testSpatialRelationshipOneToOne |
1 | 240.62s | Logs |
LegacyTransactionsConsoleClientTest::testPartialFailureRollback |
1 | 240.59s | Logs |
LegacyTransactionsCustomServerTest::testBulkUpsertOperations |
1 | 240.40s | Logs |
✨ Benchmark results
⚡ Benchmark Comparison
|
attempt to fix #11482