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

[0.7.3] Erreur à la création d'un site sur un champ caché #388

Open
PaulLabruyere opened this issue Dec 10, 2024 · 4 comments
Open

[0.7.3] Erreur à la création d'un site sur un champ caché #388

PaulLabruyere opened this issue Dec 10, 2024 · 4 comments

Comments

@PaulLabruyere
Copy link

Bonjour !

J'ai observé une petite régression suite la màj de notre module monitoring de 0.6.0 à 0.7.3.

Dans notre sous-module de suivi de gîtes chiros, on a surchargé le champ TYPE_SITE pour qu'il ne soit pas affiché dans le formulaire de création de site. On lui attribue une valeur par défaut "Site pour le suivi des chiroptères" (fichier site.json)

{
  "specific": {

    "id_nomenclature_type_site": {
      "type_widget": "datalist",
      "attribut_label": "Type site",
      "api": "nomenclatures/nomenclature/TYPE_SITE",
      "application": "GeoNature",
      "default": {
        "cd_nomenclature": "CHI"
      },
      "keyValue": "id_nomenclature",
      "keyLabel": "label_fr",
      "data_path": "values",
      "type_util": "nomenclature",
      "required": true,
      "hidden": true
    }
  }
}

(pour info, le champ tel que défini dans la configuration centralisée)

{
  "generic": {
    "id_nomenclature_type_site": {
      "type_widget": "text",
      "attribut_label": "Type site",
      "type_util": "nomenclature",
      "value": {
        "code_nomenclature_type": "TYPE_SITE" 
      },
      "required": true
    },
  }
}

Lorsque j'essaye de créer un site, j'ai l'erreur suivante (dans /var/log/geonature/geonature.log) :

[2024-12-10 16:00:08 +0000] [714913] [ERROR] Exception on /monitorings/object/gn_module_monitoring_chiro/site [POST]
Traceback (most recent call last):
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
    self.dialect.do_execute(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.DatatypeMismatch: column "id_nomenclature_type_site" is of type integer but expression is of type hstore
LINE 1: ..., altitude_min, altitude_max) VALUES (2461629, 1, hstore(ARR...
                                                             ^
HINT:  You will need to rewrite or cast the expression.


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

Traceback (most recent call last):
  File "/home/geonatureadmin/gn_module_monitoring/backend/gn_module_monitoring/monitoring/repositories.py", line 113, in create_or_update
    DB.session.commit()
  File "<string>", line 2, in commit
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1454, in commit
    self._transaction.commit(_to_root=self.future)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 832, in commit
    self._prepare_impl()
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 811, in _prepare_impl
    self.session.flush()
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3449, in flush
    self._flush(objects)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3589, in _flush
    transaction.rollback(_capture_exception=True)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3549, in _flush
    flush_context.execute()
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
    _emit_insert_statements(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 1238, in _emit_insert_statements
    result = connection._execute_20(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1710, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1577, in _execute_clauseelement
    ret = self._execute_context(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1953, in _execute_context
    self._handle_dbapi_exception(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2134, in _handle_dbapi_exception
    util.raise_(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
    self.dialect.do_execute(
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DatatypeMismatch) column "id_nomenclature_type_site" is of type integer but expression is of type hstore
LINE 1: ..., altitude_min, altitude_max) VALUES (2461629, 1, hstore(ARR...
                                                             ^
HINT:  You will need to rewrite or cast the expression.

[SQL: INSERT INTO gn_monitoring.t_base_sites (id_inventor, id_digitiser, id_nomenclature_type_site, base_site_name, base_site_description, base_site_code, first_use_date, geom, uuid_base_site, meta_create_date, meta_update_date, altitude_min, altitude_max) VALUES (%(id_inventor)s, %(id_digitiser)s, %(id_nomenclature_type_site)s, %(base_site_name)s, %(base_site_description)s, %(base_site_code)s, %(first_use_date)s, ST_GeomFromEWKT(%(geom)s), (SELECT uuid_generate_v4() AS uuid_generate_v4_1), %(meta_create_date)s, %(meta_update_date)s, %(altitude_min)s, %(altitude_max)s) RETURNING gn_monitoring.t_base_sites.id_base_site]
[parameters: {'id_inventor': 2461629, 'id_digitiser': 1, 'id_nomenclature_type_site': {'code_nomenclature_type': 'TYPE_SITE'}, 'base_site_name': 'TEST', 'base_site_description': 'site de test (màj GN 2.14.2 / monit 0.7.3), à supprimer', 'base_site_code': None, 'first_use_date': '2024-12-10', 'geom': 'SRID=4326;POINT (2.311496 49.900982)', 'meta_create_date': None, 'meta_update_date': None, 'altitude_min': None, 'altitude_max': None}]
(Background on this error at: https://sqlalche.me/e/14/f405)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/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/geonature/core/gn_permissions/decorators.py", line 62, in decorated_view
    return view_func(*args, **kwargs)
  File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/utils_flask_sqla/response.py", line 19, in _json_resp
    res = fn(*args, **kwargs)
  File "/home/geonatureadmin/gn_module_monitoring/backend/gn_module_monitoring/routes/monitoring.py", line 172, in create_object_api
    return create_or_update_object_api(module_code, object_type, id)
  File "/home/geonatureadmin/gn_module_monitoring/backend/gn_module_monitoring/routes/monitoring.py", line 139, in create_or_update_object_api
    monitoring_definitions.monitoring_object_instance(module_code, object_type, id)
  File "/home/geonatureadmin/gn_module_monitoring/backend/gn_module_monitoring/monitoring/repositories.py", line 122, in create_or_update
    raise GeoNatureError("MONITORING: create_or_update {} : {}".format(self, str(e)))
geonature.utils.errors.GeoNatureError: MONITORING: create_or_update monitoringobject gn_module_monitoring_chiro, site, None : (psycopg2.errors.DatatypeMismatch) column "id_nomenclature_type_site" is of type integer but expression is of type hstore
LINE 1: ..., altitude_min, altitude_max) VALUES (2461629, 1, hstore(ARR...
                                                             ^
HINT:  You will need to rewrite or cast the expression.

[SQL: INSERT INTO gn_monitoring.t_base_sites (id_inventor, id_digitiser, id_nomenclature_type_site, base_site_name, base_site_description, base_site_code, first_use_date, geom, uuid_base_site, meta_create_date, meta_update_date, altitude_min, altitude_max) VALUES (%(id_inventor)s, %(id_digitiser)s, %(id_nomenclature_type_site)s, %(base_site_name)s, %(base_site_description)s, %(base_site_code)s, %(first_use_date)s, ST_GeomFromEWKT(%(geom)s), (SELECT uuid_generate_v4() AS uuid_generate_v4_1), %(meta_create_date)s, %(meta_update_date)s, %(altitude_min)s, %(altitude_max)s) RETURNING gn_monitoring.t_base_sites.id_base_site]
[parameters: {'id_inventor': 2461629, 'id_digitiser': 1, 'id_nomenclature_type_site': {'code_nomenclature_type': 'TYPE_SITE'}, 'base_site_name': 'TEST', 'base_site_description': 'site de test (màj GN 2.14.2 / monit 0.7.3), à supprimer', 'base_site_code': None, 'first_use_date': '2024-12-10', 'geom': 'SRID=4326;POINT (2.311496 49.900982)', 'meta_create_date': None, 'meta_update_date': None, 'altitude_min': None, 'altitude_max': None}]
(Background on this error at: https://sqlalche.me/e/14/f405)

(notez que dans les paramètres, c'est le champ "value" de la conf générique qui est envoyé comme id_nomenclature_type_site, ce qui semble être à l'origine de l'erreur)

La route https://clicnat.fr/geonature/api/nomenclatures/nomenclature/TYPE_SITE est fonctionnelle et renvoie bien les valeurs stockées en base, dont la valeur par défaut définie dans la conf du sous-module.

Si je change la config pour enlever le hidden sur specific.id_nomenclature_type_site, le paramètre apparaît bien dans le formulaire, mais sans valeur par défaut. Les modifs que je peux faire sur le label ou la description sont en revanche bien prises en compte.

Hypothèse : il y aurait en un changement de la gestion de la conf générique et/ou des valeurs par défaut en 0.7.3 ?

@camillemonchicourt
Copy link
Member

A voir si il y a toujours le soucis en version 1.0.0 ?
Dans ce cas là la correction serait plutôt réalisée sur cette version.

@marie-laure-cen
Copy link

marie-laure-cen commented Dec 17, 2024

Version Monitoring : 0.7.3

A priori ce code fonctionne :

"id_nomenclature_type_site": {
  "attribut_label": "Type site",
  "type_util": "nomenclature",
  "value": {
    "code_nomenclature_type": "TYPE_SITE",
    "cd_nomenclature": "preloc_prat"
  },
  "hidden": true
}

@PaulLabruyere
Copy link
Author

Effectivment, en changeant ma config pour la tienne (avec "cd_nomenclature": "CHI"), je n'ai plus d'erreur et le site s'enregistre correctement.

Merci pour le tuyau ! :)

On peut fermer le ticket (même si visiblement il y a un truc uqi a changé entre 0.6 et 0.7.3 :p )

@camillemonchicourt
Copy link
Member

J'ai cherché et je ne vois pas ce qui a changé et n'en trouve pas de trace, mais en effet, il doit y avoir une différence.

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

No branches or pull requests

3 participants