Repository navigation
Description
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 withInternalServerError(500) on the first collision. insert_one()also adds_idtoself.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?
- Write a failing test first (see Tests: app-level test harness with fixtures #71): a collection with a unique index on
id, andgenerate_idpatched 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. - Generate a new ID on every POST attempt, not only when
idisNone; keep the PUT path (user-supplied ID) unchanged. - Work on a copy of the request data, and don't let
insert_oneadd_idto it (insert a copy, or remove_idbefore retrying). - 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
test: add app test harness, fix ID retry (elixir-cloud-aai#90)