Skip to content

SQLite objects created in a thread can only be used in that same thread #141

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
brgsstm opened this issue Dec 14, 2020 · 7 comments
Closed
Assignees
Labels

Comments

@brgsstm
Copy link

brgsstm commented Dec 14, 2020

I've been working on my final project for a few weeks now and everything was working well until I had to rebuild my virtual environment recently. I'm now getting an intermittent error when running SQL queries via db.execute()

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

DEBUG: SELECT id, hash, profile_complete FROM users WHERE username = 'tom@tom'
INFO: 127.0.0.1 - - [14/Dec/2020 19:54:55] "POST /login HTTP/1.1" 500 -
Traceback (most recent call last):
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1204, in _execute_context
context = constructor(dialect, self, conn, *args)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 806, in _init_compiled
self.cursor = self.create_cursor()
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 1162, in create_cursor
return self._dbapi_connection.cursor()
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 1000, in cursor
return self.connection.cursor(*args, **kwargs)
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 4618292736 and this is thread id 123145406357504.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 749, in _rollback_impl
self.engine.dialect.do_rollback(self.connection)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 543, in do_rollback
dbapi_connection.rollback()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 4618292736 and this is thread id 123145406357504.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/cs50/sql.py", line 324, in execute
connection.execute(sqlalchemy.text("BEGIN"))
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
ret = self._execute_context(
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1206, in _execute_context
self._handle_dbapi_exception(
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1505, in handle_dbapi_exception
self.autorollback()
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 82, in exit
compat.raise
(value, with_traceback=traceback)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise

raise exception
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1505, in _handle_dbapi_exception
self._autorollback()
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 888, in _autorollback
self._root._rollback_impl()
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 751, in _rollback_impl
self.handle_dbapi_exception(e, None, None, None, None)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1405, in handle_dbapi_exception
util.raise
(
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise

raise exception
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 749, in _rollback_impl
self.engine.dialect.do_rollback(self.connection)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 543, in do_rollback
dbapi_connection.rollback()
sqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 4618292736 and this is thread id 123145406357504.
(Background on this error at: http://sqlalche.me/e/13/f405)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/app.py", line 2464, in call
return self.wsgi_app(environ, start_response)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "/Users/tomburgess/onedrive/projects/cs50/final/squawk7000/app.py", line 133, in login
rows = db.execute("SELECT id, hash, profile_complete FROM users WHERE username = :username",
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/cs50/sql.py", line 21, in decorator
return f(*args, **kwargs)
File "/Users/tomburgess/environments/cs50/lib/python3.8/site-packages/cs50/sql.py", line 384, in execute
raise e
RuntimeError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 4618292736 and this is thread id 123145406357504.

@brgsstm
Copy link
Author

brgsstm commented Dec 14, 2020

Package Version


astroid 2.4.2
autopep8 1.5.4
azure-common 1.1.26
azure-core 1.9.0
azure-servicebus 7.0.0
cachelib 0.1.1
certifi 2020.12.5
chardet 3.0.4
click 7.1.2
cs50 6.0.1
Flask 1.1.2
Flask-Session 0.3.2
idna 2.10
isodate 0.6.0
isort 5.6.4
itsdangerous 1.1.0
Jinja2 2.11.2
lazy-object-proxy 1.4.3
MarkupSafe 1.1.1
mccabe 0.6.1
msrest 0.6.19
oauthlib 3.1.0
pip 20.2.1
pycodestyle 2.6.0
pylint 2.6.0
python-http-client 3.3.1
requests 2.25.0
requests-oauthlib 1.3.0
sendgrid 6.4.8
setuptools 49.2.1
six 1.15.0
SQLAlchemy 1.3.20
sqlparse 0.4.1
starkbank-ecdsa 1.1.0
termcolor 1.1.0
toml 0.10.2
uamqp 1.2.12
urllib3 1.26.2
Werkzeug 1.0.1
wrapt 1.12.1

@brgsstm
Copy link
Author

brgsstm commented Dec 14, 2020

cs50==5.1.0 fixes it

@dmalan
Copy link
Member

dmalan commented Dec 14, 2020

@brgsstm, sorry about that! Mind trying this branch in your requirements.txt file?

git+git://github.com/cs50/python-cs50.git@scoped_session

@dmalan dmalan self-assigned this Dec 14, 2020
@dmalan dmalan added the bug label Dec 14, 2020
@brgsstm
Copy link
Author

brgsstm commented Dec 14, 2020

@brgsstm, sorry about that! Mind trying this branch in your requirements.txt file?

git+git://github.com/cs50/python-cs50.git@scoped_session

@dmalan Thanks, all appears to be good now!

@dmalan
Copy link
Member

dmalan commented Dec 14, 2020

Excellent. Should be fixed in 6.0.2 now!

@dmalan dmalan closed this as completed Dec 14, 2020
@brgsstm
Copy link
Author

brgsstm commented Dec 14, 2020

@dmalan Thanks, and an extra thanks to you and the team for the great CS50 content, easily the most engaging course I have ever taken!

@dmalan
Copy link
Member

dmalan commented Dec 14, 2020

Thanks for the kind words!

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

No branches or pull requests

2 participants