From 76fd909b231001eedebd6d350a8f5e8d475a9e68 Mon Sep 17 00:00:00 2001 From: Lalith Kota Date: Tue, 23 Apr 2024 13:56:54 +0530 Subject: [PATCH] G2P-2231: Registry Encryption: Fixed error upon update Signed-off-by: Lalith Kota --- g2p_registry_encryption/models/partner.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/g2p_registry_encryption/models/partner.py b/g2p_registry_encryption/models/partner.py index 02e28d4..e62a567 100644 --- a/g2p_registry_encryption/models/partner.py +++ b/g2p_registry_encryption/models/partner.py @@ -18,7 +18,7 @@ def gather_fields_to_be_enc_from_dict( ): to_be_enc = {} for each in prov.get_registry_fields_set_to_enc(): - if fields_dict.get(each, None): + if fields_dict and fields_dict.get(each, None): to_be_enc[each] = fields_dict[each] if replace: fields_dict[each] = prov.registry_enc_field_placeholder @@ -63,7 +63,9 @@ def write(self, vals): rec_values_list["is_encrypted"] = True vals = rec_values_list else: - vals = json.loads(prov.decrypt_data(encrypted_val).decode()).update(vals) + decrypted_vals = json.loads(prov.decrypt_data(encrypted_val or b"{}").decode()) + decrypted_vals.update(vals) + vals = decrypted_vals to_be_encrypted = self.gather_fields_to_be_enc_from_dict(vals, prov) vals["encrypted_val"] = prov.encrypt_data(json.dumps(to_be_encrypted).encode())