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
Fix missing inferred types in insert statements #566
Comments
@c24t, this is the most widespread error in tests, it's raised in ~200 different cases. Seems like an emulator problem to me. |
@IlyaFaer No, both the Java client and the JDBC driver require all parameters (including If real Spanner accepts this and the emulator does not, then technically this is a problem with the emulator. At the same time the emulator does not guarantee 100% compatibility with real Spanner, so it might be that this is something you will have to live with. One option could be to try to include |
I gave this a shot in c24t/python-spanner@e339d6a, but it fails (as you might expect) for non-STRING-valued columns.
There are a few django tests where all the uninferable null fields are actually STRING-like -- like I suspect there's a better way to do this, one that doesn't rely on inferring the parameter types at all. |
One approach to fix this in googleapis/python-spanner#200. |
Adding support to this would have serious performance impacts of this. In addition, real Spanner supports non-typed parameters, and the missing support for non-typed parameters for some type (DATE and TIMESTAMP) in the emulator is considered a bug: GoogleCloudPlatform/cloud-spanner-emulator#31 |
If we call
transaction.execute_sql
with missing parameters inparam_types
, we may not get an error until iterating over the over theResultSet
(even if it's empty). This errors is:InvalidArgument('Unable to infer type for parameter ....')
.spanner_dbapi.parse_utils.get_param_types
infers spanner data types from the python types. This is called downstream of django's
CursorWrapper.execute
. Among other problems, this means that we can't infer the spanner type forNone
-valued fields, and so they aren't included inparam_types
.This problem shows up following the django tutorial at
manage.py createsuperuser
, which results in these arguments totransaction.execute_sql
:Note that
a2
is missing fromparam_types
. The fieldlast_login
should be agoogle.cloud.spanner_v1.param_types.TIMESTAMP
, but we can't infer it before the call.Interestingly we only see the
InvalidArgument
error when using the emulator. The real non-emulated spanner service handles this insert without error.This problem is at least as old as 47154d1, and existed in the
spanner_dbapi
package in this repo before it was moved into python-spanner.It's not clear whether the right fix for this problem is here, in python-spanner, or in the emulator. But it does prevent us from using the emulator with apps that have models with nullable fields, including the django tutorial app.
The text was updated successfully, but these errors were encountered: