diff --git a/backend/gn_module_import/checks/sql/__init__.py b/backend/gn_module_import/checks/sql/__init__.py index e883d8d9..51b458cf 100644 --- a/backend/gn_module_import/checks/sql/__init__.py +++ b/backend/gn_module_import/checks/sql/__init__.py @@ -28,7 +28,7 @@ from geonature.core.gn_synthese.models import Synthese, TSources from ref_geo.models import LAreas, BibAreasTypes from pypnnomenclature.models import TNomenclatures, BibNomenclaturesTypes -from apptax.taxonomie.models import Taxref, CorNomListe, BibNoms +from apptax.taxonomie.models import Taxref, cor_nom_liste from pypn_habref_api.models import Habref @@ -211,9 +211,10 @@ def check_cd_nom(imprt, fields): # Filter out on a taxhub list if provided list_id = current_app.config["IMPORT"].get("ID_LIST_TAXA_RESTRICTION", None) if list_id is not None: - reference_table = join(Taxref, BibNoms).join( - CorNomListe, - sa.and_(BibNoms.id_nom == CorNomListe.id_nom, CorNomListe.id_liste == list_id), + reference_table = join( + Taxref, + cor_nom_liste, + sa.and_(cor_nom_liste.c.id_liste == list_id, Taxref.cd_nom == cor_nom_liste.c.cd_nom), ) else: reference_table = Taxref diff --git a/backend/gn_module_import/tests/test_imports.py b/backend/gn_module_import/tests/test_imports.py index 763c1746..c727824e 100644 --- a/backend/gn_module_import/tests/test_imports.py +++ b/backend/gn_module_import/tests/test_imports.py @@ -11,10 +11,10 @@ from werkzeug.datastructures import Headers from werkzeug.exceptions import Unauthorized, Forbidden, BadRequest, Conflict from jsonschema import validate as validate_json -from sqlalchemy import func +from sqlalchemy import func, insert from sqlalchemy.sql.expression import select -from apptax.taxonomie.models import BibListes, CorNomListe, BibNoms +from apptax.taxonomie.models import BibListes, cor_nom_liste from geonature.utils.env import db from geonature.core.gn_permissions.tools import ( get_scopes_by_action as _get_scopes_by_action, @@ -282,16 +282,12 @@ def sample_taxhub_list(): cd_nom = 67111 with db.session.begin_nested(): id_list_not_exist = (db.session.query(func.max(BibListes.id_liste)).scalar() or 0) + 1 - bibTaxon = db.session.query(BibNoms).filter(BibNoms.cd_nom == cd_nom).first() - if bibTaxon is None: - bibTaxon = BibNoms(cd_nom=cd_nom, cd_ref=cd_nom) - db.session.add(bibTaxon) - taxa_list = BibListes( - id_liste=id_list_not_exist, nom_liste="test", code_liste="test", picto="" - ) + taxa_list = BibListes(id_liste=id_list_not_exist, nom_liste="test", code_liste="test") db.session.add(taxa_list) with db.session.begin_nested(): - db.session.add(CorNomListe(id_nom=bibTaxon.id_nom, id_liste=taxa_list.id_liste)) + db.session.execute( + insert(cor_nom_liste).values(cd_nom=cd_nom, id_liste=taxa_list.id_liste) + ) return taxa_list diff --git a/dependencies/GeoNature b/dependencies/GeoNature index ec1f1603..dbdc3ca1 160000 --- a/dependencies/GeoNature +++ b/dependencies/GeoNature @@ -1 +1 @@ -Subproject commit ec1f160330a211a7debca96545dba67d602ff5ca +Subproject commit dbdc3ca18e1989a70cbe007f5635752eb3f6053a