Skip to content

UNIQUE constraint failed: resources.key - likely cross-project key collision in dataframer.py #129

Description

@teslajoy

Encountered the following error during g3t push --overwrite --skip_validate inside the fhir_import_export job:

sqlite3.IntegrityError: UNIQUE constraint failed: resources.key

in log

/root/venv/lib/python3.12/site-packages/gen3_tracker/meta/dataframer.py\\\", line 161, in bulk_insert_data\\n    new_cursor = self.cursor.executemany(sql, _iterate(_resources=resources))\\n                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\nsqlite3.IntegrityError: UNIQUE constraint failed: resources.key\\n\"]}"}

This likely stems from how resources.key is constructed in dataframer.py, currently as:

key = f"{resourceType}/{id}"

I double-checked the mint-ids and they aren't duplicates on my side, so it seems like the issue comes from the same resourceType/id showing up across different program/projects? this is surprising to me. Since the key doesn’t include program or project context, they end up colliding in the shared SQLite resources table.

Recommended fix:

Update the function signature and logic in bulk_insert_data() to namespace keys:

def bulk_insert_data(self, resources, program="", project=""):
    rows = []
    for res in resources:
        key = f"{program}/{project}/{res.get('resourceType')}/{res.get('id')}" <- HERE 
        res['key'] = key  # or append to rows for bulk insert
        rows.append((key, json.dumps(res)))

This should help prevent collisions across programs or projects and keep the resource keys properly isolated. I didn’t want to open a pull request before checking in - happy to contribute code here. If there’s already a re-seeding or namespacing step in place that I’ve missed/overlooked, feel free to point it out!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions