Return 404 instead of 500 when updating a couch document that does not exist - #38047
Draft
gherceg wants to merge 5 commits into
Draft
Return 404 instead of 500 when updating a couch document that does not exist#38047gherceg wants to merge 5 commits into
gherceg wants to merge 5 commits into
Conversation
gherceg
force-pushed
the
gh/fix-create-on-update-bug
branch
from
August 20, 2026 14:38
8c91c39 to
d30c334
Compare
Ensures that a 404 is returned when a couch resource that uses this helper is not found
gherceg
force-pushed
the
gh/fix-couch-resource-404s
branch
from
August 20, 2026 14:46
f94cc81 to
4465fdf
Compare
obj_get raised tastypie's NotFound, which get_detail does not catch, so a GET for an unknown id returned a 500 rather than a 404. The obj_update change is a refactor with no behavior change: put_detail already answered 404 once it stopped echoing the exception message. It replaces the duplicated Http404 conversion with the couch mixin helper.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
gherceg
force-pushed
the
gh/fix-couch-resource-404s
branch
from
August 20, 2026 14:59
4465fdf to
ffd215a
Compare
obj_get raised tastypie's NotFound, which get_detail does not catch, so a GET for an unknown or cross-domain id returned a 500. Same fix already applied to the data source resource in the previous commit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Product Description
PUTto a mobile worker or group ID that does not exist now returns 404 instead of 500.GETfor an unknown UCR data source likewise returns 404 instead of 500. (UCR'sPUTwas already fixed by #38045, this PR fixes itsGET.)Technical Summary
https://dimagi.atlassian.net/browse/SAAS-20201
#38045 is what stops tastypie creating a new object when
obj_updateraisesNotFound.CommCareUserResourceandGroupResourceboth defineobj_create, so if this PR landed on its own, aPUTto a missing ID would silently create a new mobile worker or group instead of returning 500.CouchResourceMixin.get_document_for_updatenow does the lookup and convertsObjectDoesNotExistintoNotFound, reading the document class off_meta.object_classso callers pass only ID and domain.The downside of this change is that it still relies on those creating APIs on couch resources to use this helper in the
obj_updatemethod, but ideally we aren't adding new APIs backed by couch models.Feature Flag
N/A — the UCR data source endpoints sit behind the pre-existing
USER_CONFIGURABLE_REPORTSflag.Safety Assurance
Safety story
Every affected request previously returned a 500.
Automated test coverage
Full
corehq/apps/api/tests/suite passes.QA Plan
No QA needed.
Rollback instructions
Labels & Review