Skip to content

Ch 12 - Forms - sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. #13

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

Closed
nygeog opened this issue Apr 14, 2020 · 2 comments

Comments

@nygeog
Copy link

nygeog commented Apr 14, 2020

I'm getting this error when I run app.py at the beginning and navigate to any of the package pages.

sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 123145425145856 and this is thread id 123145430401024.

Above it getting this repeating error:

Traceback (most recent call last):
  File "/Users/danielmsheehan/GitHub/data-driven-web-apps-with-flask/venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 693, in _finalize_fairy
    fairy._reset(pool)
  File "/Users/danielmsheehan/GitHub/data-driven-web-apps-with-flask/venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 880, in _reset
    pool._dialect.do_rollback(self)
  File "/Users/danielmsheehan/GitHub/data-driven-web-apps-with-flask/venv/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 538, in do_rollback
    dbapi_connection.rollback()

To start each I chapter I start by renaming the final folder to final_, This is from copying the starter folder code and naming it final and then working in that directory.

I didn't see this error in chapter 11, (and I re-ran app.py to test - not seeing this error in ch. 11). I'm thinking there may be something different in ch 12's code, maybe something was added that after following along will be updated. If so I'll close this, otherwise not sure what to do. If this is in Chapter 13 as well and persists, I'll note that here.

@nygeog nygeog changed the title Ch 12 - Forms - sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 123145425145856 and this is thread id 123145430401024. Ch 12 - Forms - sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. Apr 14, 2020
@nygeog
Copy link
Author

nygeog commented Apr 14, 2020

I saw this again in Chapter 13 on the starter code. Not exactly sure about this error but this fixed it;

in db_session.py:

engine = sa.create_engine(conn_str, echo=False, connect_args={"check_same_thread": False})

Adding connect_args={"check_same_thread": False} to create_engine() seemed to work to silence it.

Resource: https://stackoverflow.com/questions/48218065/programmingerror-sqlite-objects-created-in-a-thread-can-only-be-used-in-that-sa

@mikeckennedy
Copy link
Member

Hi @nygeog Thanks for the heads up. Using connect_args={"check_same_thread": False} is a good idea. I just updated the various chapters' projects to reflect this. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants