Skip to content

Commit

Permalink
ipython: workaround ipython history accessor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbreckenridge committed May 2, 2022
1 parent 48eb3de commit b20409f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion my/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ def _merge_histories(*sources: Results) -> Results:

def _parse_database(sqlite_database: str) -> Results:
hist = HistoryAccessor(hist_file=sqlite_database)
total_sessions: Optional[int] = hist.get_last_session_id()
try:
total_sessions: Optional[int] = hist.get_last_session_id()
except Exception:
# if database is corrupt/fails to compute sessions, skip
return
if total_sessions is None:
return
# yes, these start at 1
Expand Down
16 changes: 16 additions & 0 deletions tests/test_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@

from .common import data

import pytest

from IPython.core.history import HistoryAccessor # type: ignore[import]


# https://github.com/ipython/ipython/issues/13666
def accessor_works() -> bool:
ipython_db = str(data("ipython.sqlite"))
hist = HistoryAccessor(hist_file=ipython_db)
try:
hist.get_last_session_id()
return True
except Exception:
return False


@pytest.mark.skipif(not accessor_works(), reason="ipython historyaccessor failed")
def test_ipython() -> None:
ipython_db = str(data("ipython.sqlite"))
cmds = list(_parse_database(ipython_db))
Expand Down

0 comments on commit b20409f

Please sign in to comment.