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

Erreur web service stats division par zéro #51

Open
jpm-cbna opened this issue Jan 16, 2024 · 0 comments
Open

Erreur web service stats division par zéro #51

jpm-cbna opened this issue Jan 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jpm-cbna
Copy link
Collaborator

Le webservice "stats" soulève une erreur de division par zéro.
Elle est référencé ici: https://app-monitor.cbn-alpin.fr/cbna/issues/68?project=1

Voici le log:

Exception on /priority_flora/stats [GET]
Traceback (most recent call last):
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
    self.dialect.do_execute(
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 609, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.DivisionByZero: ERREUR:  division par zéro


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/geonat/www/geonature_v2.9.2/backend/geonature/core/gn_permissions/decorators.py", line 82, in __check_cruved_scope
    return fn(*args, **kwargs)
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/utils_flask_sqla/response.py", line 19, in _json_resp
    res = fn(*args, **kwargs)
  File "/home/geonat/www/modules/priority-flora/backend/gn_module_priority_flora/blueprint.py", line 644, in get_stats
    "calculations": statrepo.get_calculations(),
  File "/home/geonat/www/modules/priority-flora/backend/gn_module_priority_flora/repositories.py", line 385, in get_calculations
    calculations_result = db.session.query(
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3490, in one
    ret = self.one_or_none()
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3459, in one_or_none
    ret = list(self)
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3535, in __iter__
    return self._execute_and_instances(context)
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
    return meth(self, multiparams, params)
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
    ret = self._execute_context(
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
    self._handle_dbapi_exception(
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
    util.raise_(
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
    self.dialect.do_execute(
  File "/home/geonat/www/geonature_v2.9.2/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 609, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.DataError: (psycopg2.errors.DivisionByZero) ERREUR:  division par zéro

[SQL: WITH hab_infos AS
(SELECT pr_priority_flora.t_apresence.id_ap AS id_ap, pr_priority_flora.t_apresence.id_zp AS id_zp, pr_priority_flora.t_apresence.area AS area_ap, pr_priority_flora.t_apresence.id_nomenclature_habitat AS conservation_status, anon_1.type_habitat AS habitat_type, anon_2.type_perturbation AS perturbation_type, ref_nomenclatures.t_nomenclatures.label_default AS threat_level, ref_nomenclatures.t_nomenclatures.cd_nomenclature AS threat_level_code, t_nomenclatures_1.cd_nomenclature AS habitat_favorable
FROM pr_priority_flora.t_apresence LEFT OUTER JOIN pr_priority_flora.t_zprospect ON pr_priority_flora.t_zprospect.id_zp = pr_priority_flora.t_apresence.id_zp LEFT OUTER JOIN pr_priority_flora.cor_ap_area ON pr_priority_flora.cor_ap_area.id_ap = pr_priority_flora.t_apresence.id_ap LEFT OUTER JOIN ref_geo.l_areas ON ref_geo.l_areas.id_area = pr_priority_flora.cor_ap_area.id_area LEFT OUTER JOIN ref_geo.bib_areas_types ON ref_geo.bib_areas_types.id_type = ref_geo.l_areas.id_type LEFT OUTER JOIN LATERAL (SELECT pr_priority_flora.cor_ap_physiognomy.id_ap AS id_ap, string_agg(ref_nomenclatures.t_nomenclatures.label_default, %(string_agg_1)s) AS type_habitat
FROM pr_priority_flora.cor_ap_physiognomy JOIN ref_nomenclatures.t_nomenclatures ON ref_nomenclatures.t_nomenclatures.id_nomenclature = pr_priority_flora.cor_ap_physiognomy.id_nomenclature
WHERE pr_priority_flora.cor_ap_physiognomy.id_ap = pr_priority_flora.t_apresence.id_ap GROUP BY pr_priority_flora.cor_ap_physiognomy.id_ap) AS anon_1 ON true LEFT OUTER JOIN LATERAL (SELECT pr_priority_flora.cor_ap_perturbation.id_ap AS id_ap, string_agg(ref_nomenclatures.t_nomenclatures.label_default, %(string_agg_2)s) AS type_perturbation
FROM pr_priority_flora.cor_ap_perturbation JOIN ref_nomenclatures.t_nomenclatures ON ref_nomenclatures.t_nomenclatures.id_nomenclature = pr_priority_flora.cor_ap_perturbation.id_nomenclature
WHERE pr_priority_flora.cor_ap_perturbation.id_ap = pr_priority_flora.t_apresence.id_ap GROUP BY pr_priority_flora.cor_ap_perturbation.id_ap) AS anon_2 ON true LEFT OUTER JOIN ref_nomenclatures.t_nomenclatures ON ref_nomenclatures.t_nomenclatures.id_nomenclature = pr_priority_flora.t_apresence.id_nomenclature_threat_level LEFT OUTER JOIN ref_nomenclatures.t_nomenclatures AS t_nomenclatures_1 ON t_nomenclatures_1.id_nomenclature = pr_priority_flora.t_apresence.id_nomenclature_habitat
WHERE pr_priority_flora.t_zprospect.cd_nom = %(cd_nom_1)s AND pr_priority_flora.t_zprospect.cd_nom IN (SELECT taxref_1.cd_nom
FROM taxonomie.taxref AS taxref_1 JOIN taxonomie.taxref ON taxonomie.taxref.cd_ref = taxref_1.cd_ref
WHERE taxonomie.taxref.cd_nom = %(cd_nom_2)s) AND ref_geo.l_areas.area_code = %(area_code_1)s AND ref_geo.bib_areas_types.type_code = %(type_code_1)s AND pr_priority_flora.t_zprospect.date_max <= %(date_max_1)s AND pr_priority_flora.t_zprospect.date_min >= CAST(date(%(date_1)s) - CAST(concat(%(concat_1)s, %(concat_2)s) AS INTERVAL) AS DATE))
 SELECT count(distinct(hab_infos.id_zp)) AS nb_stations, sum(hab_infos.area_ap) AS area_presence, (%(sum_1)s / sum(hab_infos.area_ap)) * %(param_1)s AS threat_level, (%(sum_2)s / sum(hab_infos.area_ap)) * %(param_2)s AS habitat_favorable
FROM hab_infos]
[parameters: {'sum_1': (0.0,), 'param_1': 100, 'sum_2': (None,), 'param_2': 100, 'string_agg_1': ', ', 'string_agg_2': ', ', 'cd_nom_1': '83992', 'cd_nom_2': '83992', 'area_code_1': '93', 'type_code_1': 'REG', 'date_max_1': '2023-11-10', 'date_1': '2023-11-10', 'concat_1': 5, 'concat_2': 'YEARS'}]
(Background on this error at: http://sqlalche.me/e/13/9h9h)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

1 participant