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

IndexManager does not properly delete search database #219

Open
mrvisscher opened this issue Dec 19, 2024 · 2 comments · May be fixed by #235
Open

IndexManager does not properly delete search database #219

mrvisscher opened this issue Dec 19, 2024 · 2 comments · May be fixed by #235

Comments

@mrvisscher
Copy link

Issue in short: When you delete a searchable database and create one with the same name, you cannot properly create activities within it anymore.

When you delete a database, the IndexManager deletes the accompanied search database by dropping the tables as follows:

def delete_database(self):
with self.db.bind_ctx(MODELS):
self.db.drop_tables(MODELS)

However, this means that the database file is not removed. If you then reinstate a database with the same name IndexManager.create() is not called as os.path.exists(self.path) will validate as true.

def __init__(self, database_path):
self.path = os.path.join(projects.request_directory("search"), database_path)
self.db = SqliteExtDatabase(self.path)
if not os.path.exists(self.path):
self.create()

This in turn leads to no tables being created in the database, which in turn leads to activities not being able to be saved because of the following exception:

File "***\Lib\site-packages\bw2data\backends\proxies.py", line 356, in save
    IndexManager(Database(self["database"]).filename).update_dataset(self._data)
File "***\Lib\site-packages\bw2data\search\indices.py", line 70, in update_dataset
    ).execute()
      ^^^^^^^^^
File "***\Lib\site-packages\peewee.py", line 2036, in inner
    return method(self, database, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "***\Lib\site-packages\peewee.py", line 2107, in execute
    return self._execute(database)
           ^^^^^^^^^^^^^^^^^^^^^^^
File "***\Lib\site-packages\peewee.py", line 2625, in _execute
    cursor = database.execute(self)
             ^^^^^^^^^^^^^^^^^^^^^^
File "***\Lib\site-packages\peewee.py", line 3330, in execute
    return self.execute_sql(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "***\Lib\site-packages\peewee.py", line 3320, in execute_sql
    with __exception_wrapper__:
File "***\Lib\site-packages\peewee.py", line 3088, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "***\Lib\site-packages\peewee.py", line 196, in reraise
    raise value.with_traceback(tb)
File "***\Lib\site-packages\peewee.py", line 3322, in execute_sql
    cursor.execute(sql, params or ())
peewee.OperationalError: no such table: bw2schema
@vjousse
Copy link
Contributor

vjousse commented Jan 28, 2025

The problem comes from this commit 7bcadab#diff-156c54133bcd9d05da2cde6868077ac3de630fb179d6590080e25c48424445e3R143 and I don't see why the choice was made to not remove the file anymore, but only to remove the tables. I’ll propose a PR to fix this.

@vjousse vjousse linked a pull request Jan 28, 2025 that will close this issue
@vjousse
Copy link
Contributor

vjousse commented Jan 28, 2025

@cmutel @mrvisscher done in #235

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

Successfully merging a pull request may close this issue.

2 participants