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

Except: pass in databases metastore #187

Closed
mrvisscher opened this issue Sep 16, 2024 · 4 comments
Closed

Except: pass in databases metastore #187

mrvisscher opened this issue Sep 16, 2024 · 4 comments

Comments

@mrvisscher
Copy link

There is an undefined Except: pass in the database deletion procedure. This causes databases to be silently deleted from the metastore regardless of any errors that occurred during actual database deletion from the SQLite database. This leads to ghost databases that are not registered but do still exist.

https://github.com/brightway-lca/brightway2-data/blob/main/bw2data/meta.py#L100

def __delitem__(self, name):
    from . import Database
    try:
        Database(name).delete(warn=False)
    except:
        pass

    super(Databases, self).__delitem__(name)
@tngTUDOR
Copy link
Contributor

tngTUDOR commented Sep 17, 2024

Do you suggest we try:

def __delitem__(self, name):
    from . import Database
    try:
        Database(name).delete(warn=False)
        super(Databases, self).__delitem__(name)
    except e:
        logging.error("Something went wrong removing the db", e)

to start with, and review the whole "try/except/finally" of this feat+method ?

@cmutel
Copy link
Member

cmutel commented Sep 17, 2024

@tngTUDOR No, I think he is saying the except clause should restore the database to databases.

@mrvisscher Can you give me an example of what kind of error could arise during the SQL transaction? It should be pretty straightforward and I wouldn't have expected any errors there.

BTW, this is another thing that should change ASAP - the database and method data (even CFs) will be in the database as well.

@tngTUDOR
Copy link
Contributor

I know this is probably unrelated but some tests in 3.11 @ win arch fail with some "delete" related ops (for projects, not databases):

https://github.com/brightway-lca/brightway2-data/actions/runs/10860661234/job/30141531219#step:6:464

just leaving it here in case this could help out the coverage and / or identification of the reason why we have such test failing

@mrvisscher
Copy link
Author

Do you suggest we try:

def __delitem__(self, name):
    from . import Database
    try:
        Database(name).delete(warn=False)
        super(Databases, self).__delitem__(name)
    except e:
        logging.error("Something went wrong removing the db", e)

to start with, and review the whole "try/except/finally" of this feat+method ?

Yes this was actually what I was suggesting. We had the Database Delete action in the Activity Browser failing silently, and our tests didn't catch it because the exception never came up.

@mrvisscher Can you give me an example of what kind of error could arise during the SQL transaction? It should be pretty straightforward and I wouldn't have expected any errors there.

Any error from database lock to whatever, depending on the backend.

BTW, this is another thing that should change ASAP - the database and method data (even CFs) will be in the database as well.

Well that's just fantastic. I was discussing this at our side not so long ago as well. Happy to hear that's being planned.

@cmutel cmutel closed this as completed in d223b95 Sep 19, 2024
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

3 participants