fix(azure_ai_search): use a value-safe delimiter for search.in filters - #3846
fix(azure_ai_search): use a value-safe delimiter for search.in filters#3846chakshu-dhannawat wants to merge 2 commits into
Conversation
|
Heads-up for maintainers This PR is from a fork and touches integrations whose integration tests require API keys. Affected integrations:
Please run the integration tests locally ( |
Coverage report (azure_ai_search)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Azure's search.in() splits its value-list string on the supplied delimiter. The previous implementation always used a comma, which collided with commas inside metadata values (e.g. "New York, NY"), causing the server to split a single value into multiple fragments. Pick a delimiter that does not appear in any of the values. If every candidate delimiter is present, fall back to an OR chain of eq comparisons. Update unit-test expectations and add a regression test for values that contain commas.
a86a232 to
cc9c408
Compare
| # Pick a delimiter that does not occur in any of the values, so commas (or | ||
| # any other character) inside metadata values are preserved. If every | ||
| # candidate delimiter is present, fall back to an OR chain of eq clauses. | ||
| candidates = ["\u001f", "\u001e", "\u001d"] |
There was a problem hiding this comment.
Lets expand the candidate list to include common delimiters since its possible that the values don't contain the common ones
candidates = [",", "|", ";", "\u001f", "\u001e", "\u001d"]
| if all(delimiter not in v for v in value): | ||
| values = delimiter.join(_escape_odata_literal(v) for v in value) | ||
| return f"search.in({field},'{values}','{delimiter}')" | ||
| return " or ".join(f"{field} eq '{_escape_odata_literal(v)}'" for v in value) |
There was a problem hiding this comment.
Lets make sure to expand the unit tests to cover this branch, currently it doesn't look like its covered.
Fixes #3844
Azure's
search.in(field, valueList, delimiter)splitsvalueListon the supplied delimiter before comparing. The previous implementation always joined values with a comma and passed,as the delimiter, so any metadata value that itself contained a comma (e.g."New York, NY") was split apart by Azure's server-side parsing and never matched.Changes:
_in()now picks a delimiter that does not occur in any of the supplied values (candidates: U+001F, U+001E, U+001D).eqcomparisons.Verified with
hatch run test:unit,hatch run test:types, andhatch run fmtinintegrations/azure_ai_search.