lmmentel / mendeleev

A python package for accessing various properties of elements, ions and isotopes in the periodic table of elements.
https://mendeleev.readthedocs.io
MIT License
220 stars 40 forks source link

Use read-only SQLite connection #165

Closed jan-janssen closed 4 months ago

jan-janssen commented 4 months ago

When the mendeleev package is located on a Network File System (NFS) Sqlalchemy fails with an OperationalError.

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) disk I/O error

This is a known limitation of SQLite:

This is because fcntl() file locking is broken on many NFS implementations. You should avoid putting SQLite database files on NFS if multiple processes might try to access the file at the same time.

As the data in the elements.db file never changes, the solution is to connect to the SQLite database using read-only mode. This is implemented in this pull request.

Originally reported by @pkruzikova

lmmentel commented 4 months ago

Thanks @jan-janssen & @pkruzikova :raised_hands:

In general the changes make sense, however I would rather have a flag that defaults to read-only mode for most cases but still allows to grab the engine for making edits and additions to the db programatically. I might be the only person who's doing that atm but wouldn't want to duplicate the function for the "dev" mode. Could you add a flag to get_engine and get_session to parametrize the access mode?

There seem to be some small linting errors, that should be easy to fix.

jan-janssen commented 4 months ago

Could you add a flag to get_engine and get_session to parametrize the access mode?

@lmmentel I added the flag to get_engine and get_session.

There seem to be some small linting errors, that should be easy to fix.

In addition I fixed the linting errors.

lmmentel commented 4 months ago

Thanks :+1:

jan-janssen commented 4 months ago

Perfect, thanks a lot - @lmmentel Can you create a new release?

lmmentel commented 4 months ago

Yes :100: