teksi / wastewater

[DEV] Future TEKSI wastewater module, adapted data model to fit VSA-DSS 2020 new standard
https://teksi.github.io/wastewater
GNU General Public License v3.0
2 stars 5 forks source link

Error on INTERLIS Import 'Session' object has no attribute 'get' - missing minimum requirements check for sqlalchemy #455

Closed sjib closed 1 month ago

sjib commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Exact steps to reproduce the behavior:

  1. Go to 'INTERLIS Import'
  2. Choose file to import
  3. Click 'Import'
  4. See error

Expected behavior A clear and concise description of what you expected to happen. No such error warning on import. Check if sqlalchemy has required minimum version before importing / exporting (or even installing the plugin)

Screenshots / data If applicable, add screenshots or data to help explain your problem.```

Ein Fehler trat bei der Ausführung von Python-Code auf:

AttributeError: 'Session' object has no attribute 'get' 
Traceback (most recent call last):
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\teksi_wastewater_plugin.py", line 612, in actionImportClicked
    self.interlisImporterExporter.action_import()
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\gui\interlis_importer_exporter_gui.py", line 79, in action_import
    raise exception
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\gui\interlis_importer_exporter_gui.py", line 60, in action_import
    self.interlis_importer_exporter.interlis_import(
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\interlis_importer_exporter.py", line 148, in interlis_import
    raise exception
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\interlis_importer_exporter.py", line 106, in interlis_import
    tww_session = self._import_from_intermediate_schema(import_model)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\interlis_importer_exporter.py", line 261, in _import_from_intermediate_schema
    interlisImporterToIntermediateSchema.tww_import(skip_closing_tww_session=True)
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\interlis_model_mapping\interlis_importer_to_intermediate_schema.py", line 41, in tww_import
    raise exception
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\interlis_model_mapping\interlis_importer_to_intermediate_schema.py", line 33, in tww_import
    self._tww_import(skip_closing_tww_session)
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\interlis_model_mapping\interlis_importer_to_intermediate_schema.py", line 66, in _tww_import
    self._import_sia405_abwasser()
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\interlis_model_mapping\interlis_importer_to_intermediate_schema.py", line 78, in _import_sia405_abwasser
    self._import_organisation()
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\interlis_model_mapping\interlis_importer_to_intermediate_schema.py", line 654, in _import_organisation
    organisation = self.create_or_update(
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\interlis_model_mapping\interlis_importer_to_intermediate_schema.py", line 435, in create_or_update
    instance = self.session_tww.get(cls, obj_id)
               ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Session' object has no attribute 'get'

Python-Version: 3.12.4 (main, Jun 10 2024, 12:48:35) [MSC v.1938 64 bit (AMD64)] 
QGIS-Version: 3.34.8-Prizren Prizren, 91642333 

Python-Pfad:
C:/PROGRA~1/QGIS 3.34.8/apps/qgis-ltr/./python
C:/Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python
C:/Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins
C:/PROGRA~1/QGIS 3.34.8/apps/qgis-ltr/./python/plugins
C:\PROGRA~1\QGIS 3.34.8\apps\grass\grass83\etc\python
C:\Users\Stefan\Documents
C:\Program Files\QGIS 3.34.8\bin\python312.zip
C:\PROGRA~1\QGIS 3.34.8\apps\Python312\DLLs
C:\PROGRA~1\QGIS 3.34.8\apps\Python312\Lib
C:\Program Files\QGIS 3.34.8\bin
C:\Users\Stefan\AppData\Roaming\Python\Python312\site-packages
C:\PROGRA~1\QGIS 3.34.8\apps\Python312
C:\PROGRA~1\QGIS 3.34.8\apps\Python312\Lib\site-packages
C:\PROGRA~1\QGIS 3.34.8\apps\Python312\Lib\site-packages\win32
C:\PROGRA~1\QGIS 3.34.8\apps\Python312\Lib\site-packages\win32\lib
C:\PROGRA~1\QGIS 3.34.8\apps\Python312\Lib\site-packages\Pythonwin
C:/Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python
C:/Daten/QGEP/testing_2024.0.2/20241001_project-translations
C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\interlis\gui\..\..

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

sjib commented 1 month ago

https://github.com/teksi/wastewater/blob/d48313e65ff600c57f9fc5649c9810d469e92701/plugin/teksi_wastewater/interlis/interlis_model_mapping/interlis_importer_to_intermediate_schema.py#L435C29-L435C40

sjib commented 1 month ago

Check python version in OSGEO4W Shell: python --version

Check sqlalchemy version in OSGEO4W Shell: pip show sqlalchemy (see https://blog.finxter.com/how-to-check-sqlalchemy-package-version-in-python/)


Name: SQLAlchemy
Version: 1.3.24
Summary: Database Abstraction Library
Home-page: http://www.sqlalchemy.org
Author: Mike Bayer
Author-email: mike_mp@zzzcomputing.com
License: MIT
Location: C:\Users\Stefan\AppData\Roaming\Python\Python312\site-packages
Requires:
Required-by: GeoAlchemy2

It looks like session.get was introduced with version 1.4: https://docs.sqlalchemy.org/en/20/orm/session_api.html#sqlalchemy.orm.Session.get

Updating sqlalchemy: pip3 install --upgrade sqlachemy

Now I have:

C:\Program Files\QGIS 3.34.8>pip show sqlalchemy
Name: SQLAlchemy
Version: 2.0.35
Summary: Database Abstraction Library
Home-page: https://www.sqlalchemy.org
Author: Mike Bayer
Author-email: mike_mp@zzzcomputing.com
License: MIT
Location: C:\Users\Stefan\AppData\Roaming\Python\Python312\site-packages
Requires: greenlet, typing-extensions
Required-by: GeoAlchemy2

@domi4484 / @ponceta So we should set this as minimal requirement on tww. Can you add these to the plugin code and check for it? Are there other minimal requirements?

Else it is very difficult to find out what these kind of error messages are about.

sjib commented 1 month ago

see also https://github.com/teksi/wastewater/issues/439#issuecomment-2392944059