commcare-hq icon indicating copy to clipboard operation
commcare-hq copied to clipboard

Catch ResourceNotFound when update groups for mobile worker

Open jingcheng16 opened this issue 1 year ago • 1 comments

Product Description

Happen to notice that we didn't catch the scenario that the group id does not exist at all. This uncaught error resulted in our error message are not very helpful also misleading:

➜  ~ curl -X PUT "https://staging.commcarehq.org/a/village-health/api/v0.5/user/94cxxxxxxxxxxxxxxxxxxxx/" \
     -H "Authorization: ApiKey [email protected]:2011xxxxxxxxxxxxxxxxxxxxe2" \
     -H "Content-Type: application/json" \
     -d '{"groups": ["305f7aa9a9c84acbbe3557f435d5b37d","68b0e855393ec988e9819d676735c79c","2c5c94f7a89e39d9af5faaea81a94dd5","569a196df0a9a9628043ffaddb3fe637","1a712f3b97fabc5418c37b4ebdb5ce5b","569a196df0a9a9628043ffaddb4bcc40","1a712f3b97fabc5418c37b4ebdc98d78"]}'
{"error_message": "Sorry, this request could not be processed. Please try again later."}%

After my change, API will return

{"error": "['Unable to save groups. The following group_ids are not in the current domain: 68b0e855393ec988e9819d676735c79c, 569a196df0a9a9628043ffaddb4bcc40, 305f7aa9a9c84acbbe3557f435d5b37d, 1a712f3b97fabc5418c37b4ebdb5ce5b, 569a196df0a9a9628043ffaddb3fe637, 2c5c94f7a89e39d9af5faaea81a94dd5, 1a712f3b97fabc5418c37b4ebdc98d78']"}%

Technical Summary

https://dimagi.atlassian.net/browse/SAAS-16057

Safety Assurance

Safety story

Automated test coverage

corehq.apps.api.tests.test_user_updates:TestUpdateUserMethods.test_update_groups_with_fake_group_id_raises_exception

QA Plan

QA Ticket: https://dimagi.atlassian.net/browse/QA-7136

  • Do regression test on updating groups of mobile workers via api
  • When pass an invalid group_id like "12345", should see "Unable to save groups. The following group_ids are not in the current domain:"
  • When pass an group_id, that the group existed, but not in the current domain, should also see "Unable to save groups. The following group_ids are not in the current domain:"
  • Poke around with updating groups on front end, make sure everything still work as expected

Rollback instructions

  • [x] This PR can be reverted after deploy with no further considerations

Labels & Review

  • [x] Risk label is set correctly
  • [x] The set of people pinged as reviewers is appropriate for the level of risk of the change

jingcheng16 avatar Oct 08 '24 19:10 jingcheng16

reviewed by product team. ✅ after jenny's comment is addressed

biyeun avatar Oct 09 '24 16:10 biyeun