Skip to content

BUG: HistoryAccessor.get_session_info(0) - exception #5348

@sashkab

Description

@sashkab

According to documentation, HistoryAccessor.get_session_info(0) should return information about current session. Instead, it throws exception.

In [1]: from IPython.core.history import HistoryAccessor

In [2]: h = HistoryAccessor()

In [3]: h.get_session_info(0)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-3e9c0d3a6d56> in <module>()
----> 1 h.get_session_info(0)

/Users/xxxxx/.virtualenvs/d/lib/python2.7/site-packages/IPython/core/history.pyc in get_session_info(self, session)

/Users/xxxxx/.virtualenvs/d/lib/python2.7/site-packages/IPython/core/history.pyc in needs_sqlite(f, self, *a, **kw)
     63         return []
     64     else:
---> 65         return f(self, *a, **kw)
     66
     67

/Users/xxxxx/.virtualenvs/d/lib/python2.7/site-packages/IPython/core/history.pyc in get_session_info(self, session)

/Users/xxxxx/.virtualenvs/d/lib/python2.7/site-packages/IPython/core/history.pyc in catch_corrupt_db(f, self, *a, **kw)
     79     """
     80     try:
---> 81         return f(self, *a, **kw)
     82     except DatabaseError:
     83         if os.path.isfile(self.hist_file):

/Users/xxxxx/.virtualenvs/d/lib/python2.7/site-packages/IPython/core/history.pyc in get_session_info(self, session)
    276
    277         if session <= 0:
--> 278             session += self.session_number
    279
    280         query = "SELECT * from sessions where session == ?"

AttributeError: 'HistoryAccessor' object has no attribute 'session_number'

When providing session number everything works as expected:

In [6]: h.get_session_info(session=102)
Out[6]: (102, datetime.datetime(2014, 3, 13, 9, 30, 57, 524807), None, None, u'')

As a workaround, to get current session, I'm using get_tail(n=1):

for x in h.get_tail(n=1): 
    session = x[0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions