Repository navigation
Python: fix(sqlserver): handle None and boolean expressions in SqlServerCollection lambda parser - #14687
Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
Conversation
… SqlServerCollection - Map comparisons against None (ast.Eq, ast.NotEq, ast.Is, ast.IsNot) to IS NULL / IS NOT NULL without binding parameter - Support scalar constant comparisons against None evaluated to T-SQL (1 = 1) or (1 = 0) - Bind booleans as '1' or '0' matching _cast_value and SQL Server BIT column type - Add comprehensive unit tests mirroring Postgres test_null_filter_parser Closes microsoft#14683 Signed-off-by: Wasim <wasim143mr@gmail.com>
MOHAMMED WASIM KHAN (wasim-builds)
requested a review
from a team
as a code owner
October 29, 2026 19:46
MOHAMMED WASIM KHAN (wasim-builds)
deployed
to
github-app-auth
October 29, 2026 19:46 — with
GitHub Actions
Active
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #14683
SqlServerCollection._lambda_parserrenderedNonecomparisons as[field] = ?or[field] <> ?binding the string literal'None'. Because SQL Server evaluates equality withNULLunderANSI_NULLS ONas UNKNOWN, search filters targetingNonecould never matchNULLrows. In addition:ast.Isandast.IsNotraisedNotImplementedError: Unsupported operator: <class 'ast.Is'>onx.tenant is Noneandx.tenant is not None.'True'/'False'instead of'1'/'0'(which is expected by SQL ServerBITcolumns and is already used by_cast_value).default_dynamic_filter_functiongeneratinglambda x: x.tenant == Nonebound'None'as a query parameter.Changes
SqlServerCollection._lambda_parser:(ast.Eq, ast.NotEq, ast.Is, ast.IsNot).left_nodeisast.Constantwithvalue is None, it swapsleft_nodeandright_node.None:(1 = 1)or(1 = 0).[column] IS NULL(forast.Eq,ast.Is) or[column] IS NOT NULL(forast.NotEq,ast.IsNot) without appending any parameter tocommand.parameters.NotImplementedErrorifast.Isorast.IsNotis used with a non-Noneoperand.case ast.Constant():, bind booleans as'1'ifTrueelse'0'to match_cast_valueand SQL ServerBITsemantics.right_nodeacross comparison operator branches.test_null_filter_parserintests/unit/connectors/memory/test_sql_server.pycovering 28 cases mirroring Postgres null filter parser tests (== None,!= None,is None,is not None, reversed comparisons, constant truth evaluation, compound boolean expressions, boolean bindings'1'/'0', and string'None').test_null_filter_query_parameter_orderverifying SELECT query parameter alignment when combining null filters with vector and range filters.test_dynamic_null_filterverifyingdefault_dynamic_filter_function(tenant=None)generates[tenant] IS NULLwithout parameters.test_unsupported_is_operatorverifying unsupportediscomparisons raiseNotImplementedError.Verification
uv run pytest tests/unit/connectors/memory/test_sql_server.py(73 passed in 0.16s).uv run ruff check tests/unit/connectors/memory/test_sql_server.py semantic_kernel/connectors/sql_server.py(all checks passed).uv run ruff format --check tests/unit/connectors/memory/test_sql_server.py semantic_kernel/connectors/sql_server.py(all formatted).