Skip to content

Fix std.filter and std.filterMap to reject non-boolean predicate results instead of treating them as "false"#559

Merged
stephenamar-db merged 2 commits intodatabricks:masterfrom
JoshRosen:fix/boolean-validation-in-filter-assert-v2
Dec 4, 2025
Merged

Fix std.filter and std.filterMap to reject non-boolean predicate results instead of treating them as "false"#559
stephenamar-db merged 2 commits intodatabricks:masterfrom
JoshRosen:fix/boolean-validation-in-filter-assert-v2

Conversation

@JoshRosen
Copy link
Copy Markdown
Contributor

This PR fixes a bug where filter() and filterMap() mishandled filter predicate results that weren't booleans: instead of failing with an error, jsonnet treated any non-boolean value as though it was false. For example:

std.filter(function(x) "not a boolean", [1, 2, 3])
// sjsonnet (before): [] (silently treats non-boolean as false)
// jsonnet: RUNTIME ERROR: filter function must return boolean, got: string
// go-jsonnet: RUNTIME ERROR: Unexpected type string, expected boolean

The problem was that evaluator code was checking .isInstanceOf[Val.True] rather than explicitly checking for booleans (very similar to the past issue fixed in #44).

This PR's fix is to update this logic to use .asBoolean , which throws an explicit type error for non-booleans:

sjsonnet.Error: Wrong parameter type: expected Boolean, got string
JoshRosen and others added 2 commits December 4, 2025 00:23
…ling

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@stephenamar-db stephenamar-db merged commit 9131c50 into databricks:master Dec 4, 2025
6 checks passed
@JoshRosen JoshRosen deleted the fix/boolean-validation-in-filter-assert-v2 branch December 6, 2025 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants