Term Import Internal Server Error after deleting all Tags
Closed this issue · 4 comments
Description
The Term Import function fails when trying to import terms after deleting all the tags with the Update Exiting Terms
checkbox enabled.
To Reproduce
Steps to reproduce the behavior, e.g.:
- Load the default dev build
- Import the terms with the provided csv file (out100.csv)
- Delete all the term tags via the user interface
- Attempt to re-import the original terms from the same csv file with the
Update Existing Terms
checkbox enabled.
Term Import File
Screenshots
Full Stack Trace
Traceback (most recent call last):
File "/home/user/lute-dev/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1934, in _exec_single_context
self.dialect.do_executemany(
File "/home/user/lute-dev/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 918, in do_executemany
cursor.executemany(statement, parameters)
sqlite3.IntegrityError: UNIQUE constraint failed: wordtags.WtWoID, wordtags.WtTgID
The above exception was the direct cause of the following exception:
... [SNIP] ...
sqlalchemy.exc.IntegrityError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely)
(sqlite3.IntegrityError) UNIQUE constraint failed: wordtags.WtWoID, wordtags.WtTgID
[SQL: INSERT INTO wordtags ("WtTgID", "WtWoID") VALUES (?, ?)]
[parameters: [(1, 1), (2, 1)]]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
Well, this is a dumb oversight somehow. When I go into the UI and delete the term tags, the data in the association table isn't cleared out:
sqlite> select * from tags;
sqlite>
sqlite> select * from wordtags;
1|1
1|2
Have to check further, thank you for catching it @cblanken .
Hm, this is odd. I added a test to verify that deleting the TermTag
entity also deletes the association record in the wordtags
table, and that test passed.
The "delete" button on the Term Tag listing calls lute/termtag/routes.py
delete
route, which does the same thing as the test: gets an item by its id, and deletes and commits it. The test is deleting it, the route is not.
I've added this test to the develop
branch in b9083320b
Fixed (with a hack) in develop
.
Launched in 3.5.1.