denisenkom / pytds

Python DBAPI driver for MSSQL using pure Python TDS (Tabular Data Stream) protocol implementation
MIT License
192 stars 53 forks source link

cursor._session is None when iterating over cursor directly #59

Closed jmartinez-jobsity closed 7 years ago

jmartinez-jobsity commented 8 years ago

When running something like:

with pytds.connect(as_dict=True, **settings.mssql) as conn:
    with conn.cursor() as cursor:
        cursor.callproc(self.SP_NAME)
        for row in cursor:
            print(row)

I'm getting a 'NoneType' object has no attribute 'fetchone' from the _session being None

> /usr/lib/python3.5/site-packages/pytds/__init__.py(744)fetchone()
-> row = self._session.fetchone()
(Pdb) self._session is None
True

For now, the workaround is to iterate over cursor.fetchall(), but I think iterating over the cursor directly should not raise that exception

denisenkom commented 7 years ago

Can you provide full stack trace? Also can you test it on current tip of master branch?

jmartinez-jobsity commented 7 years ago

Seems to be fixed now