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

pr_zh empty : Exception on /zones_humides/pbf [GET] #10

Closed
cen-cgeier opened this issue Nov 7, 2022 · 1 comment
Closed

pr_zh empty : Exception on /zones_humides/pbf [GET] #10

cen-cgeier opened this issue Nov 7, 2022 · 1 comment

Comments

@cen-cgeier
Copy link
Contributor

cen-cgeier commented Nov 7, 2022

Version de GéoNature : 2.9.2

Contexte :
Module fraîchement installé.
Table pr_zh.t_zh : vide

message d'erreur :

Exception on /zones_humides/pbf [GET]
Traceback (most recent call last):
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    return self.finalize_request(rv)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.8/site-packages/flask/app.py", line 1967, in finalize_request
    response = self.make_response(rv)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.8/site-packages/flask/app.py", line 2096, in make_response
    raise TypeError(
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

source :
https:://mongeonature/geonature/api/zones_humides/pbf

Ce renvoi d'erreur concerne également l'api :
https:://mongeonature/geonature/api/zones_humides/pbf/complete

Cause potentiel :
Le servie getPbf (défini dans gn_module_ZH/frontend/app/services/zh-data.service.ts) veut absolument retourner responseType: "blob" mais get_pbf (défini dans gn_module_ZH/backend/blueprint.py) ne lui retourne rien si pr_zh.t_zh est vide.

@blueprint.route("/pbf", methods=["GET"])
def get_pbf():
    sql = """
    SELECT ST_AsGeobuf(q, 'geom') as pbf
    FROM (SELECT id_zh, geom from pr_zh.t_zh tz) AS q;
    """
    query = DB.session.execute(sql)
    row = query.first()
    if row["pbf"]:
        return Response(bytes(row["pbf"]), mimetype="application/protobuf")

Solution potentiel :
Ajouter une clause else à la fonction get_pbf

@blueprint.route("/pbf", methods=["GET"])
def get_pbf():
    sql = """
    SELECT ST_AsGeobuf(q, 'geom') as pbf
    FROM (SELECT id_zh, geom from pr_zh.t_zh tz) AS q;
    """
    query = DB.session.execute(sql)
    row = query.first()
    if row["pbf"]:
        return Response(bytes(row["pbf"]), mimetype="application/protobuf")
    else : 
        return Response(bytes('No actual data','utf-8'), mimetype="application/protobuf")

Qu'en disent vos regards d'expert ?
Même si en soit, je présume que le problème ne devrait plus exister dès lors qu'une zone humide est recensée dans la bdd.

@camillemonchicourt
Copy link
Member

Corrigé dans la version 1.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants