saketkc / pysradb

Package for fetching metadata and downloading data from SRA/ENA/GEO
https://saketkc.github.io/pysradb
BSD 3-Clause "New" or "Revised" License
307 stars 50 forks source link

Error not thrown when entering wrong db path #26

Closed DaasDaham closed 4 years ago

DaasDaham commented 4 years ago

Description

If SRAmetadab.sqlite is not already downloaded on local machine using $ pysradb metadb, then when using db = SRAdb('xyz.sqlite') throws an exception metaInfo not found which is hard-coded on line 158 in sradb.py. Ideally, it should check if the file with the name entered already exists or not and throw the error on line 153 in sradp.py not a valid SRAmetadb.sqlite file. It, however, creates a new .sqlite file with the given address ('xyz.sqlite' in this case) and tries SELECT * from metaInfo on it. Therefore, it would never enter the except block on line 153.

What I Did

from pysradb import SRAdb
db = SRAdb('this_shouldnt_exist')
df = db.sra_metadata('SRP098789')
df.head()

It returns

Traceback (most recent call last):
  File "sample.py", line 2, in <module>
    db = SRAdb('this_shouldnt_exist')
  File "/usr/local/lib/python3.6/dist-packages/pysradb/sradb.py", line 178, in __init__
    _verify_srametadb(sqlite_file)
  File "/usr/local/lib/python3.6/dist-packages/pysradb/sradb.py", line 155, in _verify_srametadb
    metadata = db.query("SELECT * FROM metaInfo")
  File "/usr/local/lib/python3.6/dist-packages/pysradb/basedb.py", line 103, in query
    results = self.cursor.execute(sql_query).fetchall()
sqlite3.OperationalError: no such table: metaInfo

and doing an ls on current dir shows the file with the name entered has been created

saad@DaasDaham:~$ ls
Desktop    examples.desktop  Public             sample.py  this_shouldnt_exist
Documents  Music             pysradb_downloads  snap       Videos
Downloads  Pictures          R                  Templates