Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
psadil opened this issue Oct 1, 2024 · 0 comments
Open

Comments

@psadil
Copy link

psadil commented Oct 1, 2024

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)
        ):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant