Skip to content

Index on a table containing columns with no sort order fails while reflecting the table #399

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

Closed
mmahmed opened this issue Jun 11, 2024 · 3 comments · Fixed by #485
Closed
Assignees
Labels
api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mmahmed
Copy link

mmahmed commented Jun 11, 2024

Environment details

  • Programming language: Python
  • OS: debian (can be reproduce on any OS)
  • Language runtime version: Python 3.11.7
  • Package version: sqlalchemy-spanner==1.7.0, SQLAlchemy==1.4.49

Steps to reproduce

  1. Install Packages:
 pip install SQLAlchemy==1.4.49 sqlalchemy-spanner==1.7.0

  1. Setup Engine:
from sqlalchemy import create_engine

# Replace the following with your actual database connection string
DATABASE_URL = "spanner+spanner:///projects/YOUR_PROJECT_ID/instances/YOUR_INSTANCE_ID/databases/YOUR_DATABASE_ID"
engine = create_engine(DATABASE_URL)
  1. Setup Database:
# SQL for creating the table
create_table_sql = """
CREATE TABLE clicks (
  id INT64 NOT NULL,
  date DATE NOT NULL,
  url_hash STRING(32) NOT NULL,
  url STRING(MAX) NOT NULL,
) PRIMARY KEY(id, date DESC, url_hash);
"""

# SQL for creating the index
create_index_sql = """
CREATE INDEX idx_on_clicks ON clicks(id, date DESC, url_hash) STORING (url);
"""

# Execute the SQL commands
with engine.connect() as connection:
    connection.execute(create_table_sql)
    connection.execute(create_index_sql)

  1. Reflect Database:
from sqlalchemy import MetaData, inspect

inspector = inspect(engine)
meta = MetaData(bind=engine)
MetaData.reflect(meta, views=True)
  1. Exception from Step 4:
  File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 614, in __new__
    table._init(name, metadata, *args, **kw)
  File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 689, in _init
    self._autoload(
  File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 724, in _autoload
    conn_insp.reflect_table(
  File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 807, in reflect_table
    self._reflect_indexes(
  File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 1071, in _reflect_indexes
    if k in c_sorting:
       ^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

Note: SQLAlchemy-2.0.30 also has the same issue.

@mmahmed mmahmed added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jun 11, 2024
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API. label Jun 11, 2024
@mmahmed mmahmed changed the title Column Order Attributes on Index Index on a table containing columns with no sort order fails while reflecting the table Jun 11, 2024
@mmahmed
Copy link
Author

mmahmed commented Jun 12, 2024

Hi @harshachinta - Can you please check this issue and the attached PR. I have updated the issue with detailed steps to reproduce. Please let me know if you need any information.

@mmahmed
Copy link
Author

mmahmed commented Jun 14, 2024

Hi @ankiaga - Can you please check this issue and the attached PR. Please let me know if you need any information.

@harshachinta harshachinta assigned ankiaga and unassigned harshachinta Jun 14, 2024
@ankiaga ankiaga assigned olavloite and unassigned ankiaga Jun 14, 2024
@mmahmed
Copy link
Author

mmahmed commented Jul 2, 2024

Hi @olavloite - Can you please check this issue and the attached PR. Please let me know if you need any information.

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-sqlalchemy API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
4 participants