Skip to content

update_redcap_record does not update fields when the value was NULL #23

@psadil

Description

@psadil

update_redcap_record compares and old record object with a new one, attempting to update any fields that have changed, and then passing the updated object to the vbr_client.update_row for updating the database:

def update_redcap_record(
self, redcap_form_name: str, redcap_record: RcapTable, rcap_row: RcapTable
) -> RcapTable:
"""Update RedCap row based on RedCap API response"""
for k,v in redcap_record.dict().items():
old_value = rcap_row.dict().get(k,None)
if old_value is not None and old_value != v:
setattr(rcap_row,k,v)
rcap_row = self.vbr_client.update_row(rcap_row)
return rcap_row

But the comparison of old vs new values prevents updating when the old values were None (e.g., can't fill a previously NULL value)

            if old_value is not None and old_value != v:

I think this should be something like

       if (
            (old_value is None and v is not None)
            or (old_value is not None and v is None)
            or (old_value != v)
        ):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions