Skip to content
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

ExecuteSqlRequest params only takes strings #1165

Open
AkanshDivker opened this issue Jul 12, 2024 · 0 comments
Open

ExecuteSqlRequest params only takes strings #1165

AkanshDivker opened this issue Jul 12, 2024 · 0 comments
Assignees
Labels
api: spanner Issues related to the googleapis/python-spanner API.

Comments

@AkanshDivker
Copy link

I don't know if this is expected behaviour or if I'm doing something wrong, but I'm trying to migrate to using the SpannerAsyncClient API. When passing the params object to ExecuteSqlRequest, I get a parsing error if the values in params are not all strings. Is this expected behaviour? This wasn't the case with the high-level API.

On another note, values returned from queries are not their correct types even though the metadata lists their correct types.

Error:

google.api_core.exceptions.FailedPrecondition: 400 Could not parse number_value: 0
 as INT64

Code:

sql = """
            SELECT dream_id, title, timestamp, tags, tag_ids, types
            FROM RecentDreams
            WHERE user_id = @user_id AND timestamp <= @timestamp AND timestamp >= @max_timestamp
            ORDER BY timestamp DESC
            LIMIT @limit OFFSET @offset
            """

params = {
            "user_id": user_id,
            "timestamp": timestamp,
            "max_timestamp": max_timestamp,
            "limit": page_size,
            "offset": start_offset,
}

param_types_dict = {
            "user_id": param_types.STRING,
            "timestamp": param_types.TIMESTAMP,
            "max_timestamp": param_types.TIMESTAMP,
            "limit": param_types.INT64,
            "offset": param_types.INT64,
}

request = ExecuteSqlRequest(
            session=session.name,
            transaction=transaction,
            sql=sql,
            params=params,
            param_types=param_types_dict ,
)

 result = await self.spanner.execute_sql(request=request)

The above works without error if page_size and start_offset are passed as strings instead of integers.

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner API. label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner API.
Projects
None yet
Development

No branches or pull requests

2 participants