Skip to content

[Bug]: Python fulltext score label cannot be selected by SQLAlchemy #32026

Description

@Ariznawlll

Description

FulltextFilter.label() returns a custom FulltextLabel object which SQLAlchemy does not accept as a selectable column. Consequently applications cannot project the relevance score using the advertised label in a standard SQLAlchemy select() query; construction fails before a query reaches MatrixOne.

Environment

  • Official MatrixOne main: f0a6ed145e07c84ecc80566ac659212c4a20debd.
  • Python 3.12, SQLAlchemy 1.4.54 and 2.1.6; offline, no MO service needed.
  • The SDK was run from clean commit d24f446e1e94a58c329d422519f7aad621cdcd05; the entire clients/python/matrixone package is byte-identical to the official main commit above (git diff is empty).

Steps to reproduce

from sqlalchemy import Column, Integer, MetaData, Table, Text, select
from matrixone.sqlalchemy_ext.fulltext_search import boolean_match

docs = Table('docs', MetaData(), Column('id', Integer), Column('body', Text))
score = boolean_match(docs.c.body).must('needle').label('score')
print(select(docs.c.id, score))

Actual behavior

sqlalchemy.exc.ArgumentError: Column expression, FROM clause, or other columns clause element expected, got ... FulltextLabel ... (SQLAlchemy 2.1.6; 1.4.54 reports the same kind of ArgumentError).

Expected behavior

The expression should be selectable and compile to a score projection such as SELECT docs.id, MATCH(...) AGAINST(...) AS score FROM docs.

Stability and controls

  • Fresh expressions reproduced the exception 3/3 times under each SQLAlchemy version.
  • select(docs.c.id).where(boolean_match(docs.c.body).must('needle')) compiles normally.
  • Calling SQLAlchemy's ColumnElement.label on the same filter compiles a projection with AS score; this is a compilation control, not a claim of a live server result.
  • The failure occurs during client-side statement construction; no database operation or data mutation occurs.

Code analysis

clients/python/matrixone/sqlalchemy_ext/fulltext_search.py: FulltextFilter subclasses ColumnElement, but its overridden label returns an ad-hoc object rather than a SQLAlchemy selectable expression. The existing offline label tests check .compile() on the ad-hoc object and do not insert it into a SQLAlchemy select().

Regression coverage

Add a client offline regression that uses the public .label() in select(), verifies the rendered label and exercises supported SQLAlchemy versions; add an online relevance-score check separately when an environment is available.

Related

Related exploration of SDK query composition: #32018. This is distinct from its additional WHERE predicate grouping defect.

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions