COSIMA / cosima-cookbook

Framework for indexing and querying ocean-sea ice model output.
https://cosima-recipes.readthedocs.io/en/latest/
Apache License 2.0
57 stars 27 forks source link

SQL PRAGMA Error #313

Closed dpath2o closed 1 year ago

dpath2o commented 1 year ago

Currently logged into are.nci.org.au but same error/issue happens via PBS submitted job. I have tested on all available conda environments and same error happens. (Things were working fine earlier in the day ... it seems like some update must have happened).

Here is sequence of commands issued that reproduce the error: import cosima_cookbook as cc session = cc.database.create_session()

which results in


OperationalError Traceback (most recent call last) File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/sqlalchemy/engine/base.py:1900, in Connection._execute_context(self, dialect, constructor, statement, parameters, execution_options, *args, **kw) 1899 if not evt_handled: -> 1900 self.dialect.do_execute( 1901 cursor, statement, parameters, context 1902 ) 1904 if self._has_events or self.engine._has_events:

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/sqlalchemy/engine/default.py:736, in DefaultDialect.do_execute(self, cursor, statement, parameters, context) 735 def do_execute(self, cursor, statement, parameters, context=None): --> 736 cursor.execute(statement, parameters)

OperationalError: attempt to write a readonly database

The above exception was the direct cause of the following exception:

OperationalError Traceback (most recent call last) Cell In[2], line 1 ----> 1 session = cc.database.create_session() 2 cc.querying.getvar(expt='01deg_jra55v140_iaf', variable='u', session=session, n=1)

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/cosima_cookbook/database.py:543, in create_session(db, debug, timeout) 541 # if database version is 0, we've created it anew 542 conn = engine.connect() --> 543 ver = conn.execute("PRAGMA user_version").fetchone()[0] 544 if ver == 0: 545 # seems we can't use usual SQL parameter strings, so we'll just format the version in... 546 conn.execute("PRAGMA user_version={}".format(__DB_VERSION__))

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/sqlalchemy/engine/base.py:1365, in Connection.execute(self, statement, *multiparams, **params) 1356 if isinstance(statement, util.string_types): 1357 util.warn_deprecated_20( 1358 "Passing a string to Connection.execute() is " 1359 "deprecated and will be removed in version 2.0. Use the " (...) 1362 "driver-level SQL string." 1363 ) -> 1365 return self._exec_driver_sql( 1366 statement, 1367 multiparams, 1368 params, 1369 _EMPTY_EXECUTION_OPTS, 1370 future=False, 1371 ) 1373 try: 1374 meth = statement._execute_on_connection

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/sqlalchemy/engine/base.py:1669, in Connection._exec_driver_sql(self, statement, multiparams, params, execution_options, future) 1659 ( 1660 statement, 1661 distilled_params, (...) 1665 statement, distilled_parameters, execution_options 1666 ) 1668 dialect = self.dialect -> 1669 ret = self._execute_context( 1670 dialect, 1671 dialect.execution_ctx_cls._init_statement, 1672 statement, 1673 distilled_parameters, 1674 execution_options, 1675 statement, 1676 distilled_parameters, 1677 ) 1679 if not future: 1680 if self._has_events or self.engine._has_events:

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/sqlalchemy/engine/base.py:1943, in Connection._execute_context(self, dialect, constructor, statement, parameters, execution_options, *args, **kw) 1940 branched.close() 1942 except BaseException as e: -> 1943 self._handle_dbapi_exception( 1944 e, statement, parameters, cursor, context 1945 ) 1947 return result

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/sqlalchemy/engine/base.py:2124, in Connection._handle_dbapiexception(self, e, statement, parameters, cursor, context) 2122 util.raise(newraise, with_traceback=excinfo[2], from=e) 2123 elif shouldwrap: -> 2124 util.raise( 2125 sqlalchemy_exception, with_traceback=excinfo[2], from=e 2126 ) 2127 else: 2128 util.raise_(exc_info[1], with_traceback=exc_info[2])

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/sqlalchemy/util/compat.py:210, in raise_(failed resolving arguments) 207 exception.cause = replace_context 209 try: --> 210 raise exception 211 finally: 212 # credit to 213 # https://cosmicpercolator.com/2016/01/13/exception-leaks-in-python-2-and-3/ 214 # as the traceback object creates a cycle 215 del exception, replacecontext, from, with_traceback

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/sqlalchemy/engine/base.py:1900, in Connection._execute_context(self, dialect, constructor, statement, parameters, execution_options, *args, **kw) 1898 break 1899 if not evt_handled: -> 1900 self.dialect.do_execute( 1901 cursor, statement, parameters, context 1902 ) 1904 if self._has_events or self.engine._has_events: 1905 self.dispatch.after_cursor_execute( 1906 self, 1907 cursor, (...) 1911 context.executemany, 1912 )

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-22.07/lib/python3.9/site-packages/sqlalchemy/engine/default.py:736, in DefaultDialect.do_execute(self, cursor, statement, parameters, context) 735 def do_execute(self, cursor, statement, parameters, context=None): --> 736 cursor.execute(statement, parameters)

OperationalError: (sqlite3.OperationalError) attempt to write a readonly database [SQL: PRAGMA user_version] (Background on this error at: https://sqlalche.me/e/14/e3q8)

micaeljtoliveira commented 1 year ago

@dpath2o Thanks for the report. This is a known issue that happens once in a while. The most recent update (from last night) should work fine. Could you have try?

dpath2o commented 1 year ago

Thanks Micael. Indeed it is working again. My apologies for bothering you.

micaeljtoliveira commented 1 year ago

No bother at all! I needed a reminder to implement a fix to this issue ;)