anvio icon indicating copy to clipboard operation
anvio copied to clipboard

[BUG] Anvi'o should check write permissions of databases before doing computationally expensive work

Open ivagljiva opened this issue 4 years ago • 1 comments

Short description of the problem

When running anvi-run-kegg-kofams (or other computationally expensive operations that require writing to a database at the end of it), anvi'o doesn't check if you have permission to write to said database. Instead, if the database is read-only for you, it fails with a sad code traceback, after it has already done all the work. :( I think we need a sanity check for db write permissions to happen at the start of such code, so that people don't waste their resources.

anvi'o version

Development branch

Detailed description of the issue

Here is an example of the traceback you get when running anvi-run-kegg-kofams on a readonly DB. As you can see, it took 3 hours just to get to this error:

✖ anvi-run-kegg-kofams encountered an error after 3:02:08.564734
Traceback (most recent call last):
  File "/project2/meren/GITHUB/anvio/bin/anvi-run-kegg-kofams", line 59, in <module>
    main(args)
  File "/project2/meren/GITHUB/anvio/anvio/terminal.py", line 866, in wrapper
    program_method(*args, **kwargs)
  File "/project2/meren/GITHUB/anvio/bin/anvi-run-kegg-kofams", line 25, in main
    p.process_kofam_hmms()
  File "/project2/meren/GITHUB/anvio/anvio/kegg.py", line 1483, in process_kofam_hmms
    self.store_annotations_in_db()
  File "/project2/meren/GITHUB/anvio/anvio/kegg.py", line 1428, in store_annotations_in_db
    gene_function_calls_table.create(self.functions_dict)
  File "/project2/meren/GITHUB/anvio/anvio/tables/genefunctions.py", line 162, in create
    self.add_new_sources_to_functional_sources(gene_function_sources, database, drop_previous_annotations_first=drop_previous_annotations_first)
  File "/project2/meren/GITHUB/anvio/anvio/tables/genefunctions.py", line 150, in add_new_sources_to_functional_sources
    database.remove_meta_key_value_pair('gene_function_sources')
  File "/project2/meren/GITHUB/anvio/anvio/db.py", line 129, in inner
    return func(self, *args, **kwargs)
  File "/project2/meren/GITHUB/anvio/anvio/db.py", line 201, in remove_meta_key_value_pair
    self._exec('''DELETE FROM self WHERE key="%s"''' % key)
  File "/project2/meren/GITHUB/anvio/anvio/db.py", line 315, in _exec
    ret_val = self.cursor.execute(sql_query)
sqlite3.OperationalError: attempt to write a readonly database

ivagljiva avatar Mar 22 '21 18:03 ivagljiva

Good point :( I will look into this. I think our new dbi classes could provide a smart mechanism.

meren avatar Mar 26 '21 15:03 meren

@meren, was this ever fixed? :)

ivagljiva avatar Sep 29 '23 09:09 ivagljiva

AFAICR we added some solutions to handle permission issues with centralized checks in db.py. Since it is from over 2 years ago and we haven't heard additional complaints, let's close it and come back to it later if/when something explodes :)

meren avatar Sep 29 '23 09:09 meren