Skip to content

fix: reject extra fields in organizations - #314

Merged
uniqueg merged 2 commits into
devfrom
fix/organization-extra-fields
Nov 1, 2026
Merged

uniqueg merged 2 commits into
devfrom
fix/organization-extra-fields

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #311 (finding M1 of the v1.0.0rc1 whole-repo pre-release review).

  • ExternalServiceRegister.organization now has additionalProperties: false, so POST /services and PUT /services/{serviceId} with organization fields other than name and url return 400. Before, such fields of any size (up to the 1 MiB body limit) were stored and served to everyone.
  • New startup warning warn_organization_fields() (pattern of warn_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: object also matches) are skipped.
  • Docs: docs/api.md (Registrations), docs/upgrading.md ("From 0.6.0" and "Stored services", with a mongosh command that keeps only name and url), and the schema description.

Out of scope (as in the issue): paging or an upper bound for GET /services.

Verification

  • TDD: tests/test_app.py::test_organization_extra_fields (POST and PUT, 400, nothing stored) failed before the schema change; TestWarnOrganizationFields (incl. array organizations) and test_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.
  • The reviewer ran the mongosh cleanup pipeline and the warning's query against a throwaway MongoDB 7.0.34.
  • CI: all checks passed (gate CI passed).

Review

Full lane (input validation). Round 1 found a high (the first documented mongosh update merged the organization instead of replacing it) and a medium (arrays of objects matched $type: object and would have crashed the startup); both fixed and confirmed in round 2.

Declined review findings

  • No test checks that create_app() calls warn_organization_fields() (low): none of the other warn_* calls has one either; a startup test for all of them would be a separate change.
  • The mongosh pipeline writes organization: null for 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

uniqueg and others added 2 commits November 1, 2026 12:49
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]>
@uniqueg uniqueg added this to the v1.0.0-rc1 milestone Nov 1, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 validation

sequenceDiagram
    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
Loading

Sequence diagram for startup warning of legacy organizations

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Reject unrecognized organization fields during service registration and updates.
  • Set the organization schema to disallow additional properties.
  • Document the allowed fields and resulting 400 responses.
  • Add coverage for POST and PUT validation and storage behavior.
cloud_registry/api/additions.openapi.yaml
docs/api.md
docs/upgrading.md
tests/test_app.py
Detect and report legacy services containing unsupported organization fields at startup.
  • Add a startup warning that queries object organizations and names affected services.
  • Ignore valid, absent, and non-object organizations, including arrays.
  • Register the warning in app startup and test field/schema consistency.
cloud_registry/app.py
cloud_registry/ga4gh/registry/service.py
tests/ga4gh/registry/test_service.py
Provide a documented MongoDB migration path for legacy organization data.
  • Add a mongosh pipeline that replaces stored organizations with only name and url.
  • Explain legacy-service compatibility and cleanup expectations during upgrades.
docs/upgrading.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a7961e6) to head (1e36be5).
⚠️ Report is 1 commits behind head on dev.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 1, 2026 12:24

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit ae9154f into dev Nov 1, 2026
44 checks passed
@uniqueg
uniqueg deleted the fix/organization-extra-fields branch November 1, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject extra fields in service organizations

1 participant