Skip a malformed app record instead of 500ing the whole marketplace listing#8924
Merged
kodjima33 merged 1 commit intoJul 3, 2026
Merged
Conversation
…isting get_popular_apps, get_available_apps, and get_approved_available_apps build App(**doc) in a loop over raw Firestore documents. Those listings are shared and Redis/process cached across all users, so a single malformed or legacy app document raised ValidationError and 500'd the entire page for everyone (GET /v1/apps, /v1/apps/popular, /v2/apps, /v1/approved-apps). Add a _safe_build_app helper that skips a record failing validation (returning None and logging its id plus the offending field names only) and use it at all three build sites. Adds pure unit tests for the helper.
kodjima33
approved these changes
Jul 3, 2026
kodjima33
left a comment
Collaborator
There was a problem hiding this comment.
Backend bug fix w/ tests: skip malformed app record instead of 500ing marketplace listings. Established poison-record pattern.
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.
What
The public app marketplace listings are built by looping over raw Firestore documents and constructing
App(**doc)for each, with no per-record guard:get_popular_apps()feedsGET /v1/apps/popularget_available_apps()feedsGET /v1/appsget_approved_available_apps()feedsGET /v2/appsandGET /v1/approved-appsApphas required no-default fields (id,name,category,author,description,image,capabilities). A single legacy or malformed app document that is missing one of these raisespydantic.ValidationError, which is unhandled and 500s the entire listing. Because these listings are shared and Redis/process-cached across all users, one bad record takes the marketplace down for everyone, not just its owner.Change
Add a
_safe_build_app(app_dict)helper that builds theApp, and onValidationErrorskips the record (returnsNone) and logs its id plus the offending field names only (never the field values, per the logging-security rules). Use it at all three build sites so a malformed record is dropped instead of failing the whole page.Single-file change in
backend/utils/apps.py. No change to the model, the database layer, or the routers.Test
New
backend/tests/unit/test_apps_marketplace_poison_guard.py:App.Noneinstead of raising.The helper is a pure function, so the test imports and calls it directly (functional core, no
monkeypatch, nosys.modules). Auto-discovered byscripts/select_backend_unit_tests.py --all; passes the import-purity and stub-pollution scanners.