Skip to content

Commit

Permalink
TN-3109 log error but continue, when more than a single in-progress Q…
Browse files Browse the repository at this point in the history
…NR is located. (#4163)
  • Loading branch information
pbugni authored Dec 17, 2021
1 parent 815d036 commit 2e1a2e3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion portal/models/questionnaire_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jsonschema
from sqlalchemy import or_
from sqlalchemy.dialects.postgresql import ENUM, JSONB
from sqlalchemy.orm.exc import MultipleResultsFound

from ..database import db
from ..date_tools import FHIR_datetime
Expand Down Expand Up @@ -878,7 +879,14 @@ def qnr_document_id(
else:
qnr = qnr.filter(QuestionnaireResponse.qb_iteration.is_(None))

return qnr.one()[0]
# Should always get exactly one.
# Raise attention via error log if not, but continue (TN-3109)
try:
return qnr.one()[0]
except MultipleResultsFound:
current_app.logger.error(
f"Multiple {status} QNRs found for user {subject_id} on qb_id {questionnaire_bank_id}")
return qnr.first()[0]


def consolidate_answer_pairs(answers):
Expand Down

0 comments on commit 2e1a2e3

Please sign in to comment.