Skip to content

Python: Search() keeps a falsy value instead of treating it as Blank - #8974

Open
Grapette.L (Lesereingrape) wants to merge 2 commits into
microsoft:mainfrom
Lesereingrape:fix/powerfx-search-falsy-value
Open

Grapette.L (Lesereingrape) wants to merge 2 commits into
microsoft:mainfrom
Lesereingrape:fix/powerfx-search-falsy-value

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

Motivation & Context

Search() in the declarative Power Fx evaluator dropped a search value whenever that value was falsy, so a numeric 0, a 0.0 or False became "" and matched every row instead of the rows that actually carry that value. Fixes #8973.

rows = [{"code": 0}, {"code": 10}, {"code": 2}]
search_table(rows, 0, "code")    # main: all 3 rows   -> expected [0, 10]
search_table(rows, "0", "code")  # main: [0, 10]      (same target as text works)

The asymmetry is reachable from the public API: WorkflowState.eval('=Search(Workflow.Inputs.rows, Workflow.Inputs.thr, "code")') with thr = 0 returns the whole table.

Description & Review Guide

  • What are the major changes? search_table now builds its needle with if value is not None instead of if value, and two regression tests were added for 0 and False.
  • What is the impact of these changes? Only calls whose value is falsy-but-not-Blank change behaviour: they search for 0/false as before-intended. None (Blank) and "" still match every row, so test_search_table_none and test_search_table_empty_value are untouched and pass.
  • What do you want reviewers to focus on? Whether Blank-vs-falsy should be the boundary here. Power Fx treats only Blank as "no search string", and every other helper in this module already guards with is not None (find at 318, upper at 338, lower at 354, concat_strings at 370, the loop at 401), so this brings Search in line with its neighbours rather than inventing a new convention.

Related Issue

Fixes #8973

Contribution Checklist

  • The code builds clean without any errors or warnings (left open on purpose: the agent ran ruff check / ruff format --check clean and the declarative PowerFx + workflow-state test modules green, but did not run the repo's typing task locally)
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Disclosure: this PR was written and run by an AI agent operating this account; no human has reviewed the diff. The test box above refers to the agent's own runs on main @ 6967986f.

search_table built its needle with `if value else`, so a numeric 0, 0.0 or
False became "" and matched every row: Search(rows, 0, "code") returned the
whole table while Search(rows, "0", "code") returned the two matching rows.
Power Fx only treats Blank as match-all, and the rest of this module already
guards with `is not None`, so use that here and keep None and "" matching
everything.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Oct 2, 2026

This branch was successfully deployed

1 active deployment
github-app-auth — 01426b2d Deployed Oct 3, 2026 by Lesereingrape via add_label #24339
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: declarative Search() treats a falsy value (0, 0.0, False) as Blank and returns every row

2 participants