-
Notifications
You must be signed in to change notification settings - Fork 42
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
"None" in collection is translated to an empty value instead of null value #201
Comments
Opened upstream (Datastax python driver) issue - https://datastax-oss.atlassian.net/jira/software/c/projects/PYTHON/issues/PYTHON-1355 |
@Lorak-mmk @avelanarius, have you seen this issue ? |
For reference, Java Driver 3.x has a client-side check that disallows I agree we should change it in Python Driver. Java Driver 3.x approach seems reasonable. However, changing it could potentially break some existing user code, but I guess this is a very rare usecase. This will be the place we'll add the additional check: python-driver/cassandra/cqltypes.py Lines 834 to 838 in 5afb73d
|
...although now I've been made aware (in https://github.com/scylladb/scylla-dtest/commit/e2cc40b4835f6699afd35de9d237a8083b4a5532) that there's one usecase where a
In this case it's OK to send |
Fixes scylladb#201 When using parepared statements, None values in collections were serialized as empty values (values with length == 0). This is unexpected and inconsistent - None values are serialized as NULLs (vlaues with length == -1) in other cases: - Statement arguments, both for simple and prepared statements - Collection elements in simple statement This commit fixes this weird behavior - now None values should be serialized as NULLs in all cases.
Fixes scylladb#201 When using parepared statements, None values in collections were serialized as empty values (values with length == 0). This is unexpected and inconsistent - None values are serialized as NULLs (vlaues with length == -1) in other cases: - Statement arguments, both for simple and prepared statements - Collection elements in simple statement This commit fixes this weird behavior - now None values should be serialized as NULLs in all cases. It also adds an integration test that checks new behavior.
Fixes scylladb#201 When using parepared statements, None values in collections were serialized as empty values (values with length == 0). This is unexpected and inconsistent - None values are serialized as NULLs (vlaues with length == -1) in other cases: - Statement arguments, both for simple and prepared statements - Collection elements in simple statement This commit fixes this weird behavior - now None values should be serialized as NULLs in all cases. It also adds an integration test that checks new behavior.
Fixes #201 When using parepared statements, None values in collections were serialized as empty values (values with length == 0). This is unexpected and inconsistent - None values are serialized as NULLs (vlaues with length == -1) in other cases: - Statement arguments, both for simple and prepared statements - Collection elements in simple statement This commit fixes this weird behavior - now None values should be serialized as NULLs in all cases. It also adds an integration test that checks new behavior.
Mentioned in the upstream issue, https://datastax-oss.atlassian.net/jira/software/c/projects/PYTHON/issues/PYTHON-1355, that this was solved in the ScyllaDB fork. I think it should be done upstream - there's nothing Scylla-specific about this patch. |
Fixes scylladb#201 When using parepared statements, None values in collections were serialized as empty values (values with length == 0). This is unexpected and inconsistent - None values are serialized as NULLs (vlaues with length == -1) in other cases: - Statement arguments, both for simple and prepared statements - Collection elements in simple statement This commit fixes this weird behavior - now None values should be serialized as NULLs in all cases. It also adds an integration test that checks new behavior.
I opened this PR in upstream |
This issue exists also in the Datastax driver, so it should probably be fixed in both but I'm reporting it here for now.
Normally, passing the Python value
None
as a bind value for a prepared statement passes the CQL null value - i.e., a value with length=-1.However, it seems that when we bind a collection type, and it includes a None as one of the elements, e.g., the list
['hello', None]
, the driver mistakenly converts theNone
not to null but to an empty value (value with length=0) which is probably not what we want.For example, consider that we have a table with schema
p int primary key, v list<text>
, and do:What we'd expect this to do is to attempt to to insert
null
into the list, basically the same thing as the unprepared statementINSERT INTO {table} (p,v) VALUES ({p}, ['hi', null])
. This attempt should be refused by the server, because nulls elements not allowed in collections. But what the driver does instead is to send the empty value for thisNone
. In the case of the string this is nothing else than an empty string - so basically Scylla is told to write an empty string... Instead of the write failing, it succeeds and if we now docql.execute(f"SELECT * FROM {table} WHERE p={p}"))
the result is the silly[(p, ['hello',''])]
.scylladb/scylladb#12425 contains two tests for this in Scylla's test framework which uses the Python driver to make requests. It demonstrates the situation described above for the string type (causing an empty string to be written instead of reporting an error) and also for integer type (in this case, Cassandra gets confused by the empty integer and returns some strange internal error).
The text was updated successfully, but these errors were encountered: