PnX-SI / GeoNature

Application de saisie et de synthèse des observations faune et flore
GNU General Public License v3.0
104 stars 102 forks source link

[OCCTAX - ERROR 500] api gn_profiles/check_observation #3156

Open cen-cgeier opened 3 months ago

cen-cgeier commented 3 months ago

Version Version de GeoNature affectée par le bug. 2.14.2

Description du bug image

Comportement attendu Avoir un code_status 200 à la requête api gn_profiles/check_observation

Comment reproduire Ouvrir Occtax (version web) et saisir un taxon figurant dans la vue matérialisée gn_profiles.vm_valid_profiles avec le champs active_life_stage = True

Logs

[5b40d84f-ff05-43cb-8667-4fc7b7f8f995] Exception on /gn_profiles/check_observation [POST]
Traceback (most recent call last):
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.10/site-packages/utils_flask_sqla/response.py", line 19, in _json_resp
    res = fn(*args, **kwargs)
  File "/home/geonatureadmin/geonature/backend/geonature/core/gn_profiles/routes.py", line 225, in get_observation_score
    life_stage_value = DB.get(TNomenclatures, life_stage)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 1008, in __getattr__
    raise AttributeError(name)
AttributeError: get
[2024-08-19 18:02:44 +0200] [1740666] [ERROR] Exception on /gn_profiles/check_observation [POST]
Traceback (most recent call last):
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.10/site-packages/utils_flask_sqla/response.py", line 19, in _json_resp
    res = fn(*args, **kwargs)
  File "/home/geonatureadmin/geonature/backend/geonature/core/gn_profiles/routes.py", line 225, in get_observation_score
    life_stage_value = DB.get(TNomenclatures, life_stage)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 1008, in __getattr__
    raise AttributeError(name)
AttributeError: get

Solution trouvée Remplacer DB.get par DB.get_or_404 (utilisé dans les autres fonctions) File "/home/geonatureadmin/geonature/backend/geonature/core/gn_profiles/routes.py", line 225, in get_observation_score

                # life_stage_value = DB.get(TNomenclatures, life_stage)
                life_stage_value = DB.get_or_404(TNomenclatures, life_stage)
camillemonchicourt commented 2 months ago

Merci, c'était bien ça : https://github.com/PnX-SI/GeoNature/pull/3164/files