nens / threedi-api-qgis-client

3Di Models & Simulations plugin
https://plugins.lizard.net/
Other
2 stars 0 forks source link

Migration: sqlalchemy.exc.OperationalError #592

Closed Overmeen closed 3 months ago

Overmeen commented 3 months ago

An error occurs when trying to Save to Spatialite from an older version of a 3Di geopackage (217).

Steps to reproduce:

  1. Open 3Di Geopackage
  2. Choose ROR PRI - dijktraject 13-4.gpkg
  3. Save to Spatialite
  4. Migration pop-up, select Yes
  5. Error

Link to We-Transfer for sqlite and gpkg: https://we.tl/t-5bbQ6dqvJ8

Traceback:

An error has occurred while executing Python code: 
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) duplicate column name: vegetation_stem_density [SQL: ALTER TABLE v2_cross_section_location ADD COLUMN vegetation_stem_density FLOAT] (Background on this error at: https://sqlalche.me/e/20/e3q8) 
Traceback (most recent call last):
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default/python/plugins\threedi_schematisation_editor\utils.py", line 769, in ensure_valid_schema
    schema.validate_schema()
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\threedi_schema\application\schema.py", line 146, in validate_schema
    raise MigrationMissingError(
threedi_schema.application.errors.MigrationMissingError: This tool requires at least schema version 219. Current version: 217.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

 File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\engine\base.py", line 1964, in _exec_single_context
    self.dialect.do_execute(
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\engine\default.py", line 748, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: duplicate column name: vegetation_stem_density

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

Traceback (most recent call last):
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default/python/plugins\threedi_schematisation_editor\__init__.py", line 250, in save_to_default
    self.save_to_spatialite(pick_destination=False)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default/python/plugins\threedi_schematisation_editor\__init__.py", line 290, in save_to_spatialite
    schema_is_valid = ensure_valid_schema(dst_sqlite, self.uc)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default/python/plugins\threedi_schematisation_editor\utils.py", line 780, in ensure_valid_schema
    schema.upgrade(backup=False, upgrade_spatialite_version=True)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\threedi_schema\application\schema.py", line 127, in upgrade
    _upgrade_database(self.db, revision=revision, unsafe=False)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\threedi_schema\application\schema.py", line 43, in _upgrade_database
    alembic_command.upgrade(config, revision)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\command.py", line 322, in upgrade
    script.run_env()
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\script\base.py", line 569, in run_env
    util.load_python_file(self.dir, "env.py")
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\util\pyfiles.py", line 94, in load_python_file
    module = load_module_py(module_id, path)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\util\pyfiles.py", line 110, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
  File "", line 855, in exec_module
  File "", line 228, in _call_with_frames_removed
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\threedi_schema\migrations\env.py", line 60, in 
    run_migrations_online()
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\threedi_schema\migrations\env.py", line 54, in run_migrations_online
    context.run_migrations()
  File "", line 8, in run_migrations
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\runtime\environment.py", line 853, in run_migrations
    self.get_context().run_migrations(**kw)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\runtime\migration.py", line 623, in run_migrations
    step.migration_fn(**kw)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\threedi_schema\migrations\versions\0218_1d_vegetation_and_variable_friction.py", line 38, in upgrade
    batch_op.add_column(sa.Column(column, sa.Float()))
  File "C:\PROGRA~1\3DIMOD~1.28\apps\Python39\lib\contextlib.py", line 124, in __exit__
    next(self.gen)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\operations\base.py", line 381, in batch_alter_table
    impl.flush()
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\operations\batch.py", line 111, in flush
    fn(*arg, **kw)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\ddl\impl.py", line 322, in add_column
    self._exec(base.AddColumn(table_name, column, schema=schema))
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\alembic\ddl\impl.py", line 195, in _exec
    return conn.execute(construct, multiparams)
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\engine\base.py", line 1414, in execute
    return meth(
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\sql\ddl.py", line 181, in _execute_on_connection
    return connection._execute_ddl(
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\engine\base.py", line 1526, in _execute_ddl
    ret = self._execute_context(
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\engine\base.py", line 1842, in _execute_context
    return self._exec_single_context(
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\engine\base.py", line 1983, in _exec_single_context
    self._handle_dbapi_exception(
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\engine\base.py", line 2326, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\engine\base.py", line 1964, in _exec_single_context
    self.dialect.do_execute(
  File "C:\Users\Stijn.Overmeen\AppData\Roaming\3Di\QGIS3\profiles\default\python\plugins\threedi_results_analysis\deps\sqlalchemy\engine\default.py", line 748, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) duplicate column name: vegetation_stem_density
[SQL: ALTER TABLE v2_cross_section_location ADD COLUMN vegetation_stem_density FLOAT]
(Background on this error at: https://sqlalche.me/e/20/e3q8)