Repository navigation
fix: reject extra fields in organizations - #314
Conversation
Registrations and updates accepted any extra fields in `organization`, of any size up to the request size limit, which were stored and served to everyone (finding M1 of the rc1 pre-release review). The schema now allows only `name` and `url` (400 otherwise), and the app warns on startup of stored services with extra organization fields. The API and upgrade docs describe the change and how to clean up such services. Closes #311 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The documented mongosh update merged the literal organization into the stored one, so extra fields stayed; it now keeps only `name` and `url` (checked against MongoDB 7.0 in review). - The startup warning skips organizations that are arrays, which MongoDB's `$type: object` matches if they hold objects (the app would not start). - A test keeps the allowed fields equal to those of the schema. Refs #311 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR tightens organization validation to allow only name and url, preventing unsupported data from being stored through the API, while preserving legacy records and warning operators about them at startup. It adds schema-consistency and endpoint tests plus upgrade documentation and a MongoDB cleanup procedure. Sequence diagram for organization field validationsequenceDiagram
participant Client
participant API
participant Schema
participant Services
Client->>API: POST /services or PUT /services/{serviceId}
API->>Schema: validate ExternalServiceRegister
alt organization has only name and url
Schema-->>API: validation succeeds
API->>Services: store service
Services-->>Client: success response
else organization has extra fields
Schema-->>API: validation fails
API-->>Client: 400 Bad Request
end
Sequence diagram for startup warning of legacy organizationssequenceDiagram
participant App
participant MongoDB
participant Logger
App->>MongoDB: find services with organization $type object
MongoDB-->>App: service ids and organizations
App->>App: inspect organization fields
alt extra fields found
App->>Logger: warning with affected service ids
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #314 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2356 2366 +10
=========================================
+ Hits 2356 2366 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloud_registry/ga4gh/registry/service.py" line_range="724-727" />
<code_context>
+ they have objects).
+ """
+ ids = []
+ for service in get_collection("services").find(
+ {"organization": {"$type": "object"}},
+ {"_id": False, "id": True, "organization": True},
+ sort=[("id", 1)],
+ ):
+ organization = service["organization"]
</code_context>
<issue_to_address>
**Large registries boot slowly**
When the registry has a large service collection, especially with large legacy organization values, the startup `find` must examine the service collection to test `organization` and fetch matching organization values; `create_app()` runs it in each worker, adding another full-store pass and potentially delaying deployments as the registry grows.
Avoid adding an independent full-store pass per worker, for example by checking organization fields during an existing startup scan.
</issue_to_address>Linked issues
#311 Reject extra fields in service organizations · 5 of 5 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Add additionalProperties: false to ExternalServiceRegister.organization. |
✅ Met | The schema rejects fields other than name and url. |
| 2 | Return 400 for extra organization fields on POST and PUT. |
✅ Met | The regression test covers both /services and /services/{serviceId}. |
| 3 | Warn at startup about stored services with extra organization fields. | ✅ Met | create_app() calls warn_organization_fields(), which identifies and logs the affected service IDs. |
| 4 | Mention the change in the upgrade notes. | ✅ Met | docs/upgrading.md describes the rejection, startup warning, and options for cleaning up stored services. |
| 5 | Mention the organization field restriction in the API docs. | ✅ Met | docs/api.md states that only name and url are allowed and other fields return 400. |
Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: cloud_registry/ga4gh/registry/service.py:727
Summary
Closes #311 (finding M1 of the v1.0.0rc1 whole-repo pre-release review).
ExternalServiceRegister.organizationnow hasadditionalProperties: false, soPOST /servicesandPUT /services/{serviceId}with organization fields other thannameandurlreturn400. Before, such fields of any size (up to the 1 MiB body limit) were stored and served to everyone.warn_organization_fields()(pattern ofwarn_invalid_urls()) names stored services with extra organization fields; they are still served, but can only be updated without them. Organizations that aren't objects (e.g., arrays, which MongoDB's$type: objectalso matches) are skipped.docs/api.md(Registrations),docs/upgrading.md("From 0.6.0" and "Stored services", with amongoshcommand that keeps onlynameandurl), and the schema description.Out of scope (as in the issue): paging or an upper bound for
GET /services.Verification
tests/test_app.py::test_organization_extra_fields(POST and PUT,400, nothing stored) failed before the schema change;TestWarnOrganizationFields(incl. array organizations) andtest_organization_fields_of_schema(allowed fields equal the schema's).coverage run --source cloud_registry,scripts -m pytest: 1590 passed, 262 skipped (Helm/Docker/MongoDB-only tests); coverage 100%.pre-commit run --all-files(ruff, ruff format, semgrep, gitleaks, actionlint, ast-grep, mypy): passed.mkdocs build --strict: passed.mongoshcleanup pipeline and the warning's query against a throwaway MongoDB 7.0.34.CI passed).Review
Full lane (input validation). Round 1 found a high (the first documented
mongoshupdate merged the organization instead of replacing it) and a medium (arrays of objects matched$type: objectand would have crashed the startup); both fixed and confirmed in round 2.Declined review findings
create_app()callswarn_organization_fields()(low): none of the otherwarn_*calls has one either; a startup test for all of them would be a separate change.mongoshpipeline writesorganization: nullfor services without an organization, or fails for non-object ones (low, informational): the docs apply it only to the services the warning names, which always have object organizations.Open questions
None.
🤖 Generated with Claude Code