From 4fba5a737fdf63dee4831d019947e965aef3caf8 Mon Sep 17 00:00:00 2001 From: Tobias Messner Date: Tue, 15 Oct 2024 12:07:10 +0200 Subject: [PATCH] fix: Fix an issue where feedback that shared contact info was not sent Feedback emails are sent in a background task to decrease response latency. Unfortunately, this means that the SQLAlchemy session is already closed and none of the fields of DatabaseUser can be resolved. This bug was not found because the error messages are swallowed by the background task. The bug is fixed by turning the DatabaseUser object into a normal User object before passing it to the background task. --- backend/capellacollab/feedback/routes.py | 6 +++++- backend/capellacollab/feedback/util.py | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/capellacollab/feedback/routes.py b/backend/capellacollab/feedback/routes.py index f99b2cbd12..c1299f00cc 100644 --- a/backend/capellacollab/feedback/routes.py +++ b/backend/capellacollab/feedback/routes.py @@ -73,7 +73,11 @@ def submit_feedback( util.send_feedback_email, db, feedback, - feedback_user, + ( + users_models.User.model_validate(feedback_user) + if feedback_user + else None + ), user_agent, logger, ) diff --git a/backend/capellacollab/feedback/util.py b/backend/capellacollab/feedback/util.py index 403d3c6259..9933488d6b 100644 --- a/backend/capellacollab/feedback/util.py +++ b/backend/capellacollab/feedback/util.py @@ -51,7 +51,7 @@ def check_if_feedback_is_allowed(db: orm.Session): def format_email( feedback: models.Feedback, - user: users_models.DatabaseUser | None, + user: users_models.User | None, user_agent: str | None, ) -> email_models.EMailContent: rating = feedback.rating.value @@ -76,7 +76,7 @@ def format_email( message_list.append("---") message_list.append( - f"You receive this email because you're registered as feedback recipient in the " + f"You received this email because you're registered as feedback recipient in the " f"Capella Collaboration Manager ({config.general.scheme}://{config.general.host}:{config.general.port})." ) message_list.append( @@ -105,7 +105,7 @@ def format_email( def send_feedback_email( db: orm.Session, feedback: models.Feedback, - user: users_models.DatabaseUser | None, + user: users_models.User | None, user_agent: str | None, logger: logging.LoggerAdapter, ):