incuna / django-pgcrypto-fields

Transparent field level encryption for Django using the pgcrypto postgresql extension.
BSD 2-Clause "Simplified" License
230 stars 50 forks source link

fix batch_update #377

Open gongdao123 opened 3 years ago

gongdao123 commented 3 years ago

Fix a crashing issue when using bulk_update:

Before fix, the query for bulk_update will be cast as: pgp_sym_encrypt((CASE WHEN ("crm_contact"."id" = %s) THEN pgp_sym_encrypt(%s, 'xxxxxxx_pgcrypto_key') ELSE NULL END)::bytea, 'xxxxxxx_pgcrypto_key')

Which will give error like: django.db.utils.ProgrammingError: function pgp_sym_encrypt(bytea, unknown) does not exist LINE 1: UPDATE "crm_contact" SET "phone_number_pgp" = pgp_sym_encryp... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.

The newly added code will check if the {value} needs to be encrypted.