Repository navigation
fix(sessions): same-day sessions no longer crash log/invoice lookup - #537
Merged
Merged
Conversation
A client can have several Sessions on one date: the calendar import keys on date + time, and a reschedule (cancel + rebook at the same slot) leaves a cancelled twin behind. session_log_create and InvoiceFormsetMixin.attach_sessions_to_formset both used get_or_create(client, session_date), which raised MultipleObjectsReturned. Both now pick from the day's live (non-cancelled) sessions when any exist, preferring one not yet logged / not yet billed, and only create a Session when none exists. An invoice item that already links a session on the same date keeps it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Posting a new session log raised
MultipleObjectsReturned: get() returned more than one Session -- it returned 2!for a client who had been rescheduled: the original event was cancelled and a new one booked at the same date and time, leaving twoSessionrows (one cancelled) on that date. The calendar import keys sessions on date + time, so several sessions per date are legitimate, but two sites looked them up by date only viaget_or_create:session_log_create(views/clinical_views.py)InvoiceFormsetMixin.attach_sessions_to_formset(views/crud_mixins.py), the same crash when saving an invoice item dated on such a dayFix
Both sites now:
Sessiononly when none exists for that date.The log view still redirects to editing the existing log when every candidate already has one. An invoice item already linked to a session on the same date keeps its link on edit.
Tests
Six new tests in
test_clinical.pyandtest_views_invoice_billing.py:./dev.py test --fastpasses.🤖 Generated with Claude Code