Skip to content

Reloading sample data fails with duplicate-key 500s #27

Description

@prdai

Symptom

Pressing the sample-data loader against a server that already holds (some of) the sample resources fails partway through:

5/8 bundles loaded — Server returned HTTP 500: {"issue":[{"code":"exception","diagnostics":"batch insert into resources: ERROR: duplicate key value violates unique constraint \"resources_pkey\" (SQLSTATE 23505)"}]}

Root cause

The sample bundles' transaction entries use POST but each entry.resource carries an id. Per the FHIR create interaction the server ignores client-supplied ids, but wso2/fhir-server honors them (createInTx keeps body["id"]), so a second load reuses the same ids and hits the resources primary key.

The embedded ids are inert otherwise: inter-entry references all use urn:uuid fullUrls, contained (#) references, or conditional (identifier=) references — none use Type/id form (verified across the bundles).

Fix sketch (client-side)

Strip resource.id from POST entries in loadSampleData before submitting. Implemented and verified on branch prdai-archive:fix/sample-loader-idempotent (same bundle POSTs twice with 200s against the compose FHIR server; 104/104 tests) — see closed #26 for the diff. A PR will follow.

An alternative/complementary server-side fix (make bundle POST entries always mint server ids per spec) belongs in wso2/fhir-server.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PQQK8BwmSJzs2qqbmHqNuV

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions