-
Notifications
You must be signed in to change notification settings - Fork 270
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
Trying to INSERT None results in CompileError #154
Labels
Comments
Thank you. Should be fixed in 7.0.1. |
Hi @kzidane and @dmalan root@43095595abf1:/cs50chain/app# pip3 list | grep cs50
cs50 9.2.0
root@43095595abf1:/cs50chain/app# python3
Python 3.10.4 (main, May 28 2022, 13:14:58) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cs50 import SQL
>>> db = SQL("sqlite:///database.db")
>>> db.execute("select * from test")
[]
>>> db.execute("insert into test values (?, ?)", 1, 'null string')
1
>>> db.execute("select * from test")
[{'id': 1, 'data': 'null string'}]
>>> db.execute("insert into test values (?, ?)", 2, None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/site-packages/cs50/sql.py", line 28, in decorator
return f(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/cs50/sql.py", line 190, in execute
_args = ", ".join([str(self._escape(arg)) for arg in args])
File "/usr/local/lib/python3.10/site-packages/cs50/sql.py", line 190, in <listcomp>
_args = ", ".join([str(self._escape(arg)) for arg in args])
File "/usr/local/lib/python3.10/site-packages/cs50/sql.py", line 489, in _escape
return __escape(value)
File "/usr/local/lib/python3.10/site-packages/cs50/sql.py", line 479, in __escape
sqlalchemy.types.NullType().literal_processor(self._engine.dialect)(value))
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/sqltypes.py", line 3237, in process
raise exc.CompileError(
sqlalchemy.exc.CompileError: Don't know how to render literal SQL value: None |
Sorry about that, |
Perfect! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm working on a project where sometimes I have to insert a None value into the database. This would be done in a way like this:
The database schema allows the column to be NULL.
However, this results in an error:
sqlalchemy.exc.CompileError: Don't know how to render literal SQL value: None
I tried testing just this insert statement by itself, on a fresh install, just to be sure.
which resulted in the following traceback:
The problem seems to be with line 465 in sql.py (from manual testing and the traceback) with
sqlalchemy.types.NullType().literal_processor(self._engine.dialect)(value)
Trying to call
sqlalchemy.types.NullType().literal_processor(self._engine.dialect)(None)
directly results in the same error.The problem can be fixed by changing
to
since None is always going to be NULL.
I've gotten the same problem on both Ubuntu 20.04 and Windows 10, using the same setup as I described above. Both were running Python 3.8.5 and cs50 6.0.4.
The text was updated successfully, but these errors were encountered: