Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reraise exceptions when debugging #2167

Merged
merged 6 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from django.utils.safestring import SafeData
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_noop
from django_fsm import FSMIntegerField, transition
from django_fsm.signals import post_transition

Expand Down Expand Up @@ -958,6 +959,8 @@
evaluation_results_evaluations.append(evaluation)
evaluation.save()
except Exception: # noqa: PERF203
if settings.DEBUG:
raise

Check warning on line 963 in evap/evaluation/models.py

View check run for this annotation

Codecov / codecov/patch

evap/evaluation/models.py#L963

Added line #L963 was not covered by tests
logger.exception(
'An error occured when updating the state of evaluation "%s" (id %d).', evaluation, evaluation.id
)
Expand Down Expand Up @@ -2059,17 +2062,16 @@

def send_to_user(self, user, subject_params, body_params, use_cc, additional_cc_users=(), request=None):
if not user.email:
warning_message = (
f"{user.full_name_with_additional_info} has no email address defined. Could not send email."
)
message = gettext_noop("{} has no email address defined. Could not send email.")
log_message = message.format(user.full_name_with_additional_info)
# If this method is triggered by a cronjob changing evaluation states, the request is None.
# In this case warnings should be sent to the admins via email (configured in the settings for logger.error).
# If a request exists, the page is displayed in the browser and the message can be shown on the page (messages.warning).
if request is not None:
logger.warning(warning_message)
messages.warning(request, _(warning_message))
logger.warning(log_message)
messages.warning(request, _(message).format(user.full_name_with_additional_info))

Check warning on line 2072 in evap/evaluation/models.py

View check run for this annotation

Codecov / codecov/patch

evap/evaluation/models.py#L2071-L2072

Added lines #L2071 - L2072 were not covered by tests
else:
logger.error(warning_message)
logger.error(log_message)
return

cc_users = set(additional_cc_users)
Expand Down Expand Up @@ -2109,6 +2111,8 @@
if send_separate_login_url:
self.send_login_url_to_user(user)
except Exception:
if settings.DEBUG:
raise

Check warning on line 2115 in evap/evaluation/models.py

View check run for this annotation

Codecov / codecov/patch

evap/evaluation/models.py#L2115

Added line #L2115 was not covered by tests
logger.exception(
'An exception occurred when sending the following email to user "%s":\n%s\n',
user.full_name_with_additional_info,
Expand Down
2 changes: 1 addition & 1 deletion evap/staff/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def find_matching_internal_user_for_email(request, email):
return matching_users[0]


def bulk_update_users(request, user_file_content, test_run): # noqa: PLR0912
def bulk_update_users(request, user_file_content, test_run):
# pylint: disable=too-many-branches,too-many-locals
# user_file must have one user per line in the format "{username},{email}"
imported_emails = {clean_email(line.decode().split(",")[1]) for line in user_file_content.splitlines()}
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ ignore = [
"COM812", # incompatible with formatter
"N802", # not as mighty as pylint's invalid-name https://github.com/astral-sh/ruff/issues/7660
"PLR0913", # we can't determine a good limit for arguments. reviews should spot bad cases of this.
"PLR2004", "PLW2901"
"PLR2004", "PLW2901",
"PLR0912", # sevaral ruff bugs: https://www.github.com/astral-sh/ruff/issues/11313, https://www.github.com/astral-sh/ruff/issues/11205
]

ignore-init-module-imports = true
Expand Down
Loading