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

Make updates to gpkg_contents (and other metadata tables) more robust #491

Closed
olsen232 opened this issue Oct 8, 2021 · 1 comment
Closed

Comments

@olsen232
Copy link
Collaborator

olsen232 commented Oct 8, 2021

From koordinates/kart-qgis-plugin#18

"I had a repo with two layers, removed one of them, and it was ok. But later I tried to reset the main branch to a few commits before (where it still had two layers), and got this error:

[12764] Failed to execute script kart_cli
Traceback (most recent call last):
File "lib\site-packages\sqlalchemy\engine\base.py", line 1707, in _execute_context
File "lib\site-packages\sqlalchemy\engine\default.py", line 716, in do_execute
pysqlite3.dbapi2.IntegrityError: UNIQUE constraint failed: gpkg_contents.table_name
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "kart_cli.py", line 4, in 
File "kart\cli.py", line 333, in entrypoint
File "lib\site-packages\click\core.py", line 829, in __call__
File "lib\site-packages\click\core.py", line 782, in main
File "kart\cli.py", line 157, in invoke
File "lib\site-packages\click\core.py", line 1259, in invoke
File "lib\site-packages\click\core.py", line 1066, in invoke
File "lib\site-packages\click\core.py", line 610, in invoke
File "lib\site-packages\click\decorators.py", line 21, in new_func
File "kart\checkout.py", line 360, in reset
File "kart\checkout.py", line 48, in reset_wc_if_needed
File "kart\working_copy\base.py", line 1140, in reset
File "kart\working_copy\base.py", line 849, in write_full
File "kart\working_copy\gpkg.py", line 249, in _write_meta
File "lib\site-packages\sqlalchemy\orm\session.py", line 1670, in execute
File "lib\site-packages\sqlalchemy\engine\base.py", line 1521, in _execute_20
File "lib\site-packages\sqlalchemy\sql\elements.py", line 314, in _execute_on_connection
File "lib\site-packages\sqlalchemy\engine\base.py", line 1400, in _execute_clauseelement
File "lib\site-packages\sqlalchemy\engine\base.py", line 1750, in _execute_context
File "lib\site-packages\sqlalchemy\engine\base.py", line 1931, in _handle_dbapi_exception
File "lib\site-packages\sqlalchemy\util\compat.py", line 211, in raise_
File "lib\site-packages\sqlalchemy\engine\base.py", line 1707, in _execute_context
File "lib\site-packages\sqlalchemy\engine\default.py", line 716, in do_execute
sqlalchemy.exc.IntegrityError: (pysqlite3.dbapi2.IntegrityError) UNIQUE constraint failed: gpkg_contents.table_name
[SQL: INSERT INTO gpkg_contents (table_name, data_type, identifier, description, srs_id) VALUES (?, ?, ?, ?, ?)]
[parameters: ('buildings', 'features', 'buildings: buildings', None, 2193)]
(Background on this error at: http://sqlalche.me/e/14/gkpj)

We can make more careful updates so as not to violate unique constraints.

@olsen232
Copy link
Collaborator Author

olsen232 commented Oct 8, 2021

More detail: the updates we make work as long as kart is the only one making them - in this case however the user has manually made an edit and not made it as cleanly as kart would. However, kart should still be robust enough to sort this out without crashing.

olsen232 added a commit that referenced this issue Oct 13, 2021
Kart updates a GPKG working copy, keeping user tables and metadata tables
such as gpkg_contents, spatial indexes, etc in sync. If the user edits
these metadata tables - or deletes a user table without updating the
metadata tables accordingly - then kart can fail when it tries to update
them next. Fix is to be less fussy when updating the metadata tables.
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

1 participant