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

Cannot reuse a deleted database name #236

Open
graham2071 opened this issue Feb 3, 2025 · 1 comment
Open

Cannot reuse a deleted database name #236

graham2071 opened this issue Feb 3, 2025 · 1 comment

Comments

@graham2071
Copy link

graham2071 commented Feb 3, 2025

I experienced strange behaviors while trying to make LCA computations.
First time the project is created and setup, everything works fine but next calls result in failures of the kind:

    def execute_sql(self, sql, params=None, commit=None):
        if commit is not None:
            __deprecated__('"commit" has been deprecated and is a no-op.')
        logger.debug((sql, params))
        with __exception_wrapper__:
            cursor = self.cursor()
>           cursor.execute(sql, params or ())
E           peewee.OperationalError: no such table: bw2schema

../../../../.local/share/mise/installs/python/3.12.5/lib/python3.12/site-packages/peewee.py:3322: OperationalError

After some investigation, it results the issue comes from the fact I am reusing a database.

I've created a failing unit test in bw2data to illustrate that, which I would expect to pass:

@bw2test
def test_new_activity_on_deleted():
    database = Database("a database 2")
    database.register()
    act = database.new_activity("foo", this="that", name="something")
    act.save()

    del databases["a database 2"]

    database = Database("a database 2")
    database.register()
    act = database.new_activity("foo", this="that", name="something")
    act.save()

It fails because:

  • when deleting the database, the search pickle is not removed
  • and when recreated, the tables are created only the pickle file does not exists

I am not sure how to fix properly, however I propose at least a workaround for those who encounter the same issue:
Call make_searchable when trying to reuse a db (this forces the creation of tables).

Edit:
Another workaround if you don't need the db to be searchable, register the db with searchable=False

database.register(searchable=False)

This should be faster.

@mrvisscher
Copy link

Related to #219

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

2 participants