Skip to content

Commit

Permalink
Remove _provenance from sample.details for comparison purposes
Browse files Browse the repository at this point in the history
When detecting data changes in sample upsert function, timestamp changes in the `_provenance` were causing otherwise unchanged records to be updated. Removing this value for comparison purposes in a copy of the dict, and retaining the original for insert and update.
  • Loading branch information
davereinhart committed Aug 24, 2023
1 parent 3d8475e commit 0422437
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/id3c/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def upsert_sample(db: DatabaseSession,
"collection_date": collection_date,
"encounter_id": encounter_id,
"additional_details": Json(additional_details) if additional_details else None,
"additional_details_without_prov": Json({k: additional_details[k] for k in additional_details if k != '_provenance'}) if additional_details else None,
"access_role": access_role,
}

Expand All @@ -226,7 +227,7 @@ def upsert_sample(db: DatabaseSession,
row(
coalesce(%(collection_date)s, collected)::timestamp,
coalesce(%(encounter_id)s::integer, encounter_id),
coalesce(details, '{}'::jsonb) || coalesce(%(additional_details)s, '{}')::jsonb
coalesce(details, '{}'::jsonb) || coalesce(%(additional_details_without_prov)s, '{}')::jsonb
)::text as metadata_changed,
row(access_role)::text != row(coalesce(%(access_role)s, access_role))::text as access_role_changed
from warehouse.sample
Expand Down

0 comments on commit 0422437

Please sign in to comment.