Skip to content

[ERP-4736] Fix patient edit page crash for self-registered patients#117

Merged
ppettitau merged 1 commit into
next_releasefrom
ERP-4736_Fix_self_registered_patient_demographics
May 21, 2026
Merged

[ERP-4736] Fix patient edit page crash for self-registered patients#117
ppettitau merged 1 commit into
next_releasefrom
ERP-4736_Fix_self_registered_patient_demographics

Conversation

@ppettitau

Copy link
Copy Markdown
Contributor

has_assigned_carer() was passing an unsaved PrimaryCarer instance (no PK) to a related ORM filter for patients with no PrimaryCarerRelationship (e.g. self-registered patients). This silently no-op'd in Django 4.x but raises a hard ValueError in Django 5.0+.

Add an instance.pk guard so unsaved instances short-circuit to False.

has_assigned_carer() was passing an unsaved PrimaryCarer instance (no PK)
to a related ORM filter for patients with no PrimaryCarerRelationship
(e.g. self-registered patients). This silently no-op'd in Django 4.x but
raises a hard ValueError in Django 5.0+.

Add an instance.pk guard so unsaved instances short-circuit to False.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Django 5.0+ crash on the patient edit page for self-registered patients by preventing an ORM filter from receiving an unsaved PrimaryCarer instance (no primary key).

Changes:

  • Add an instance.pk guard in PrimaryCarerForm.has_assigned_carer() so unsaved instances short-circuit to False.
  • Avoid triggering ValueError from Django’s ORM when filtering by an unsaved related model instance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ppettitau ppettitau merged commit 9682b05 into next_release May 21, 2026
1 check passed
@ppettitau ppettitau deleted the ERP-4736_Fix_self_registered_patient_demographics branch May 21, 2026 21:38
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

Successfully merging this pull request may close these issues.

2 participants