googleapis / python-spanner-sqlalchemy

Apache License 2.0
38 stars 28 forks source link

Ensure list of reserved words are lowercased to align with check. #319

Closed jakehilton closed 1 year ago

jakehilton commented 1 year ago

Environment details

Steps to reproduce

  1. Start local spanner emulator with project and instance setup
  2. Attempt to create a table using the "groups" reserved word that should be escaped
  3. Exception is thrown because the word is not properly detected as needing to be escaped

Sample python code: ` import os

from sqlalchemy import ( Column, Integer, MetaData, String, Table, create_engine, )

os.environ["SPANNER_EMULATOR_HOST"] = "localhost:9010" os.environ["SQLALCHEMY_SILENCE_UBER_WARNING"] = "1"

engine = create_engine( "spanner+spanner://localhost:9010/projects/test-project/instances/test-instance/databases/test-database" )

print(engine)

metadata = MetaData(bind=engine)

user = Table( 'groups', metadata, Column("user_id", Integer, primary_key=True), Column("user_name", String(16), nullable=False), )

metadata.create_all(engine)

print("all created?") `

Exception being thrown: `Exception has occurred: InvalidArgument 400 Error parsing Spanner DDL statement: CREATE TABLE groups ( user_id INT64 NOT NULL, user_name STRING(16) NOT NULL ) PRIMARY KEY (user_id) : Syntax error on line 1, column 14: Encountered 'groups' while parsing: identifier grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.INVALID_ARGUMENT details = "Error parsing Spanner DDL statement: CREATE TABLE groups ( user_id INT64 NOT NULL, user_name STRING(16) NOT NULL ) PRIMARY KEY (user_id) : Syntax error on line 1, column 14: Encountered 'groups' while parsing: identifier" debug_error_string = "UNKNOWN:Error received from peer {grpc_message:"Error parsing Spanner DDL statement: CREATE TABLE groups (\n\tuser_id INT64 NOT NULL, \n\tuser_name STRING(16) NOT NULL\n) PRIMARY KEY (user_id) : Syntax error on line 1, column 14: Encountered \'groups\' while parsing: identifier", grpc_status:3, created_time:"2023-05-15T15:36:27.22146-06:00"}"

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

File "/Users/me/repos/test/conntest.py", line 58, in metadata.create_all(engine) google.api_core.exceptions.InvalidArgument: 400 Error parsing Spanner DDL statement: CREATE TABLE groups ( user_id INT64 NOT NULL, user_name STRING(16) NOT NULL ) PRIMARY KEY (user_id) : Syntax error on line 1, column 14: Encountered 'groups' while parsing: identifier`