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

[OCCTAX] - Modification impossible si donnée saisie depuis occtax-mobile avec des champs additionnels sur le JDD. #3201

Open
systemeinfo-fdc25 opened this issue Sep 24, 2024 · 3 comments
Labels
Milestone

Comments

@systemeinfo-fdc25
Copy link

Bonjour à tous,

Utilisateur Geonature depuis quelques années, je me prête enfin à l’exercice de la description de bug. En espérant écrire au bon endroit et que le problème ne soit pas déjà signalé. Merci à vous.

Version
Geonature 2.14.2
Occtax-mobile 2.6.1.3210

Description du bug
Impossible d’éditer un relevé si celui-ci a été saisi sur Occtax-Mobile et est rattaché à un jeu de données qui possède des champs additionnels.
Lorsque le relevé est passé en édition, les champs "Observateur", "Date" et "Jeu de données" apparaissent non remplis.
Si des modifications sont apportées sur le relevé, les données ne sont pas enregistrées et apparaît une erreur.

Comportement attendu
Pouvoir éditer ces relevés comme n’importe quel relevé.

Logs

[8e95200d-8f37-4694-bfd5-76125d167c62] Exception on /occtax/OCCTAX/only/releve/4388 [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.NotNullViolation: ERREUR:  une valeur NULL viole la contrainte NOT NULL de la colonne « id_nomenclature_grp_typ » dans la relation « t_releves_occtax »
DETAIL:  La ligne en échec contient (4388, 409ccfc5-7556-47ce-aad8-582aea4ca771, 4, 12, null, null, null, null, 2024-09-22 00:00:00, 2024-09-22 00:00:00, 18:29:00, 18:29:00, null, null, null, null, null, null, web, null, 01010000206A080000653566072B732B4179EA10BFB2505941, 0101000020E6100000D2C43BC09376164000E31934F4654740, null, null, {"Vent": null, "Pluie": null, "Unite": null, "Passage": null, "A..., 4).

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

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/contrib/occtax/backend/occtax/blueprint.py", line 408, in updateReleve
releve = ReleveSchema().dump(releveHandler(request=request, releve=releve, scope=scope))
File "/home/geonatureadmin/geonature/contrib/occtax/backend/occtax/blueprint.py", line 348, in releveHandler
DB.session.commit()
File "", 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 237, in save_obj
_emit_update_statements(
File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 1001, in _emit_update_statements
c = 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.IntegrityError: (psycopg2.errors.NotNullViolation) ERREUR: une valeur NULL viole la contrainte NOT NULL de la colonne « id_nomenclature_grp_typ » dans la relation « t_releves_occtax »
DETAIL: La ligne en échec contient (4388, 409ccfc5-7556-47ce-aad8-582aea4ca771, 4, 12, null, null, null, null, 2024-09-22 00:00:00, 2024-09-22 00:00:00, 18:29:00, 18:29:00, null, null, null, null, null, null, web, null, 01010000206A080000653566072B732B4179EA10BFB2505941, 0101000020E6100000D2C43BC09376164000E31934F4654740, null, null, {"Vent": null, "Pluie": null, "Unite": null, "Passage": null, "A..., 4).

[SQL: UPDATE pr_occtax.t_releves_occtax SET id_nomenclature_grp_typ=%(id_nomenclature_grp_typ)s, date_min=%(date_min)s, date_max=%(date_max)s, altitude_min=%(altitude_min)s, altitude_max=%(altitude_max)s, id_nomenclature_tech_collect_campanule=%(id_nomenclature_tech_collect_campanule)s, id_nomenclature_geo_object_nature=%(id_nomenclature_geo_object_nature)s, meta_device_entry=%(meta_device_entry)s, geom_4326=ST_GeomFromEWKT(%(geom_4326)s), additional_fields=%(additional_fields)s WHERE pr_occtax.t_releves_occtax.id_releve_occtax = %(pr_occtax_t_releves_occtax_id_releve_occtax)s]
[parameters: {'id_nomenclature_grp_typ': None, 'date_min': datetime.date(2024, 9, 22), 'date_max': datetime.date(2024, 9, 22), 'altitude_min': None, 'altitude_max': None, 'id_nomenclature_tech_collect_campanule': None, 'id_nomenclature_geo_object_nature': None, 'meta_device_entry': 'web', 'geom_4326': 'SRID=4326;POINT (5.615798 46.796515)', 'additional_fields': '{"Unite": null, "Passage": null, "Temperature": null, "Couverture nuageuse": null, "Vent": null, "Pluie": null, "Visibilite": null, "Audition": null}', 'pr_occtax_t_releves_occtax_id_releve_occtax': 4388}]
(Background on this error at: https://sqlalche.me/e/14/gkpj)
[2024-09-24 11:35:14 +0000] [657387] [ERROR] Exception on /occtax/OCCTAX/only/releve/4388 [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.NotNullViolation: ERREUR: une valeur NULL viole la contrainte NOT NULL de la colonne « id_nomenclature_grp_typ » dans la relation « t_releves_occtax »
DETAIL: La ligne en échec contient (4388, 409ccfc5-7556-47ce-aad8-582aea4ca771, 4, 12, null, null, null, null, 2024-09-22 00:00:00, 2024-09-22 00:00:00, 18:29:00, 18:29:00, null, null, null, null, null, null, web, null, 01010000206A080000653566072B732B4179EA10BFB2505941, 0101000020E6100000D2C43BC09376164000E31934F4654740, null, null, {"Vent": null, "Pluie": null, "Unite": null, "Passage": null, "A..., 4).

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

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/contrib/occtax/backend/occtax/blueprint.py", line 408, in updateReleve
releve = ReleveSchema().dump(releveHandler(request=request, releve=releve, scope=scope))
File "/home/geonatureadmin/geonature/contrib/occtax/backend/occtax/blueprint.py", line 348, in releveHandler
DB.session.commit()
File "", 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 237, in save_obj
_emit_update_statements(
File "/home/geonatureadmin/geonature/backend/venv/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 1001, in _emit_update_statements
c = 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.IntegrityError: (psycopg2.errors.NotNullViolation) ERREUR: une valeur NULL viole la contrainte NOT NULL de la colonne « id_nomenclature_grp_typ » dans la relation « t_releves_occtax »
DETAIL: La ligne en échec contient (4388, 409ccfc5-7556-47ce-aad8-582aea4ca771, 4, 12, null, null, null, null, 2024-09-22 00:00:00, 2024-09-22 00:00:00, 18:29:00, 18:29:00, null, null, null, null, null, null, web, null, 01010000206A080000653566072B732B4179EA10BFB2505941, 0101000020E6100000D2C43BC09376164000E31934F4654740, null, null, {"Vent": null, "Pluie": null, "Unite": null, "Passage": null, "A..., 4).

[SQL: UPDATE pr_occtax.t_releves_occtax SET id_nomenclature_grp_typ=%(id_nomenclature_grp_typ)s, date_min=%(date_min)s, date_max=%(date_max)s, altitude_min=%(altitude_min)s, altitude_max=%(altitude_max)s, id_nomenclature_tech_collect_campanule=%(id_nomenclature_tech_collect_campanule)s, id_nomenclature_geo_object_nature=%(id_nomenclature_geo_object_nature)s, meta_device_entry=%(meta_device_entry)s, geom_4326=ST_GeomFromEWKT(%(geom_4326)s), additional_fields=%(additional_fields)s WHERE pr_occtax.t_releves_occtax.id_releve_occtax = %(pr_occtax_t_releves_occtax_id_releve_occtax)s]
[parameters: {'id_nomenclature_grp_typ': None, 'date_min': datetime.date(2024, 9, 22), 'date_max': datetime.date(2024, 9, 22), 'altitude_min': None, 'altitude_max': None, 'id_nomenclature_tech_collect_campanule': None, 'id_nomenclature_geo_object_nature': None, 'meta_device_entry': 'web', 'geom_4326': 'SRID=4326;POINT (5.615798 46.796515)', 'additional_fields': '{"Unite": null, "Passage": null, "Temperature": null, "Couverture nuageuse": null, "Vent": null, "Pluie": null, "Visibilite": null, "Audition": null}', 'pr_occtax_t_releves_occtax_id_releve_occtax': 4388}]
(Background on this error at: https://sqlalche.me/e/14/gkpj)

Contournement
Désactiver les champs additionnels le temps de pouvoir modifier les relevés concernés.

@camillemonchicourt
Copy link
Member

OK merci pour ce retour clair et précis.
C'est le bon endroit et ce n'est pas encore remonté.
Il y a certainement une différence dans la manière dont sont renseignés les relevés venant de Occtax-mobile et ceux saisis dans Occtax-web. Et cela n'a pas été identifié lors de nos tests concentrés sur l'application web.
Il faut donc investiguer le soucis pour le corriger au niveau de GeoNature et/ou d'Occtax-mobile.

@camillemonchicourt camillemonchicourt added this to the 2.15 milestone Sep 24, 2024
@gildeluermoz
Copy link
Contributor

J'ai eu le même soucis sur une instance mais pas sur une autre avec les mêmes versions de GN et occtax mobile. mais je n'avais pas réussi à identifier la raison.
En effet, sur l'instance où les relevés d'occtax mobile sont éditables sans bug, il n'y a pas de champs additionnels (dans aucun des JDD). Par contre sur l'instance où le bug se produit, il y a des champs additionnels dans la plupart des JDD.
Donc, bien vu, c'est probablement le fait d'ajouter ou pas des champs additinonnels sur les JDD qui provoque ce bug.

Pour le contourner temporairement, j'ai rempli en SQL tous les champs additionnal_fields qui sont null avec une valeur json vide :
update pr_occtax.t_releves_occtax set additional_fields = '{}' where additional_fields is null;

Après ça, les relevés sont éditables normalement mais il faut refaire la manip régulièrement pour "corriger" les relevés qui rentrent après la modif en SQL.

@camillemonchicourt
Copy link
Member

OK j'aurai pensé que #2945 réglait le soucis.
Mais peut-être que j'ai mal compris et que ça a introduit le soucis ou n'y change rien.

@jacquesfize jacquesfize modified the milestones: 2.15, 2.16 Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants