Code bug
ActiveModel::UnknownAttributeError
unknown attribute 'email_type' for MemberEmail. raise UnknownAttributeError.new(self, name) ^^^^^
In one line
Updating a member email for a member with no Medplum patient id writes `email_type` straight to the MemberEmail model, which has no such column, so it raises UnknownAttributeError.
Checked against the code
What happened
- `MemberEmailPolicy#permitted_attributes` allows `email_type`, `communication_from_clinic` and `login_access_for_patient_portal`.
- `db/schema.rb` `member_emails` has none of those columns, because email_type now lives in Medplum.
- When `medplum_target` returns :local (member has no `medplum_patient_id`), `update_locally` calls `@member_email.update!(member_email_params)`, which raises when the client sends `email_type`.
- There are only 11 events from 1 user over 14 days. The path is hit only for non-Medplum members when the client sends `email_type`. It is not a deploy side effect. The code on releases/master is unchanged, so it is not fixed.
What to do next
- Code fix In app/controllers/v1/member_emails_controller.rb, change `update_locally` to call `@member_email.update!(member_email_params.except(:email_type, :communication_from_clinic, :login_access_for_patient_portal))`. Make the same change in `create_locally` for `MemberEmail.create!`. Both calls fail if the client sends one of these keys.
- Query
Shows non-Medplum members who still have emails, and so can reach the local update path.
SELECT m.id, m.medplum_patient_id FROM members m JOIN member_emails me ON me.member_id = m.id WHERE m.medplum_patient_id IS NULL AND me.deleted_at IS NULL LIMIT 20;
Queries are shown, never run. Check them before using them on production.
Ask a follow-up
Continues the same session, so it still remembers the error and the code it read.
Analysed 1 h ago · claude-sonnet-5-5 · $0.08