Skip to content

Bug: service ID retry never generates a new ID #72

Closed

Description

@uniqueg

Why?

RegisterService.register_metadata() (cloud_registry/ga4gh/registry/service.py:53-95) is supposed to retry with a new random ID when an insert fails with DuplicateKeyError. It never generates a new ID:

  • The ID is generated only if self.data["id"] is None (line 65). After the first attempt, self.data["id"] is set, so all 10 attempts insert the same ID, and the request fails with InternalServerError (500) on the first collision.
  • insert_one() also adds _id to self.data, which is the caller's request dict (self.data = data, line 45). The retries therefore also collide on _id.

Verified with mongomock and a unique index on id: with one existing service AAAAAA and generate_id returning AAAAAA, then BBBBBB, the call raises InternalServerError, and generate_id is called only once. After the call, the caller's dict has gained the keys id and _id.

With 6-character IDs over 36 characters, collisions are rare today, but the code path exists to handle them, and the existing test for it (#71) passes for the wrong reason.

How?

  1. Write a failing test first (see Tests: app-level test harness with fixtures #71): a collection with a unique index on id, and generate_id patched to return a colliding ID and then a free one; assert that the second ID is used. Add a test that exhausting all retries returns 500.
  2. Generate a new ID on every POST attempt, not only when id is None; keep the PUT path (user-supplied ID) unchanged.
  3. Work on a copy of the request data, and don't let insert_one add _id to it (insert a copy, or remove _id before retrying).
  4. Log each collision at debug level.

Acceptance criteria

  • A collision on the first generated ID results in a successful POST with a different ID.
  • After all retries fail, the API returns 500 with a clear log message.
  • The caller's request dict is not modified.

Dependencies: none. Do together with #71.


Part of the ELIXIR Compute Platform WP4 sprint (M&Ds due end of December 2026).

Activity

  1. added
    priority: medium
    type: bug
    workload: hours
    ecp-wp4: M4.1
    on Oct 20, 2026
  2. added a commit that references this issue on Oct 20, 2026
    9dc7d38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ecp-wp4: M4.1priority: mediumtype: bugworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions