Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble using db cursor in Google Colaboratory Jupyter Notebook #4

Open
amzoss opened this issue Jan 13, 2023 · 4 comments
Open

Trouble using db cursor in Google Colaboratory Jupyter Notebook #4

amzoss opened this issue Jan 13, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@amzoss
Copy link

amzoss commented Jan 13, 2023

I was trying to run a copy of a notebook that worked fine previously (I think back in September 2022). The current version of the notebook is on Google Colaboratory, and it installs the latest LDLite (currently 0.0.35) with !pip install --upgrade ldlite.

It all starts okay. Connecting to FOLIO Snapshot worked fine, and I successfully completed several queries and selections. But when I try to set up a db cursor so I can follow the example for executing a SQL query (cur = db.cursor()), I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-63-9a71221bf8ff>](https://localhost:8080/#) in <module>
----> 1 cur = db.cursor()

AttributeError: 'NoneType' object has no attribute 'cursor'

If instead I change the database connection to db = ld.experimental_connect_db_sqlite(filename='ldlite-sqlite2.db'), I get an error when I try to query the LDLite instance. That is, this command

_ = ld.query(table='users', path='/users', query='cql.allRecords=1 sortby id')

yields

ldlite: querying: /users

reading           

scanning           

transforming           
---------------------------------------------------------------------------
OperationalError                          Traceback (most recent call last)
[/usr/local/lib/python3.8/dist-packages/ldlite/_jsonx.py](https://localhost:8080/#) in _transform_json(db, dbtype, table, total, quiet, max_depth)
    416                 table_j = table + '__t' if i == 0 else table + '__t' + str(i + 1)
--> 417                 _transform_data(dbtype, '', cur2, [(1, table_j)], jdict, newattrs, 1, row_ids, max_depth, {})
    418             if not quiet:

7 frames
OperationalError: no such column: False

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
[/usr/local/lib/python3.8/dist-packages/ldlite/_jsonx.py](https://localhost:8080/#) in _transform_json(db, dbtype, table, total, quiet, max_depth)
    422             pbar.close()
    423     except (RuntimeError, psycopg2.Error, sqlite3.OperationalError, duckdb.CatalogException) as e:
--> 424         raise RuntimeError('running JSON transform: ' + str(e))
    425     finally:
    426         cur.close()

RuntimeError: running JSON transform: no such column: False
@nassibnassar
Copy link
Contributor

Please try again with connect_db() using LDLite 0.0.36, which has a newer version of DuckDB.

@nassibnassar nassibnassar added the bug Something isn't working label Jan 13, 2023
@amzoss
Copy link
Author

amzoss commented Feb 3, 2023

Sorry for the delay, but I don't seem to be having any better luck with the new version of LDLite/DuckDB. The notebook installs 0.0.36 (with DuckDB 0.6.1), and I can connect with either username/password or tenant/token, but when I use db = ld.connect_db() for the database, I still get a "'NoneType' object has no attribute 'cursor'" error.

If I use ld.experimental_connect_db_sqlite(), it actually works better. The db.cursor() command works, and I can execute queries using the cursor. But with that method, .fetchdf() fails with the error "'sqlite3.Cursor' object has no attribute 'fetchdf'." I figured I would wait to submit that issue, in case the NoneType issue with DuckDB can be fixed instead.

@amzoss
Copy link
Author

amzoss commented Feb 21, 2023

This seems to have broken with version 0.0.34. Installing version 0.0.33 directly, the connect_db() function returns an object of type DuckDBPyConnection. After 0.0.33, the function returns NoneType.

@amzoss
Copy link
Author

amzoss commented Feb 21, 2023

Have confirmed that restoring the return statement to connect_db() fixes this issue. (I forked, edited the file, and then ran pip install against the fork from Google Colab. Everything that worked back in 0.0.33 worked again with the fork.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants