diff --git a/app/__init__.py b/app/__init__.py index 6fb6cf0528..5217736fc0 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -550,3 +550,22 @@ def scodoc_flash_status_messages(): f"Mode test: mails redirigés vers {email_test_mode_address}", category="warning", ) + + +def critical_error(msg): + """Handle a critical error: flush all caches, display message to the user""" + import app.scodoc.sco_utils as scu + + log(f"\n*** CRITICAL ERROR: {msg}") + send_scodoc_alarm(f"CRITICAL ERROR: {msg}", msg) + clear_scodoc_cache() + raise ScoValueError( + f""" + Une erreur est survenue. + + Si le problème persiste, merci de contacter le support ScoDoc via + {scu.SCO_DISCORD_ASSISTANCE} + + {msg} + """ + ) diff --git a/app/comp/moy_mod.py b/app/comp/moy_mod.py index dfced34ccc..1fccbda158 100644 --- a/app/comp/moy_mod.py +++ b/app/comp/moy_mod.py @@ -39,6 +39,7 @@ from dataclasses import dataclass import numpy as np import pandas as pd +import app from app import db from app.models import Evaluation, EvaluationUEPoids, ModuleImpl from app.scodoc import sco_cache @@ -484,7 +485,8 @@ class ModuleImplResultsClassic(ModuleImplResults): if nb_etuds == 0: return pd.Series() evals_coefs = self.get_evaluations_coefs(modimpl).reshape(-1) - assert evals_coefs.shape == (nb_evals,) + if evals_coefs.shape != (nb_evals,): + app.critical_error("compute_module_moy: vals_coefs.shape != nb_evals") evals_notes_20 = self.get_eval_notes_sur_20(modimpl) # Les coefs des évals pour chaque étudiant: là où il a des notes # non neutralisées