Skip to content

fix: return NULL from scalar functions given invalid argument types - #114

Merged
j6k4m8 merged 1 commit into
aplbrain:masterfrom
Sanjays2402:fix/scalar-function-invalid-argument-types
Aug 4, 2026
Merged

fix: return NULL from scalar functions given invalid argument types#114
j6k4m8 merged 1 commit into
aplbrain:masterfrom
Sanjays2402:fix/scalar-function-invalid-argument-types

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #107

toLower/toUpper/trim called the underlying str method directly and size called len(), so a non-string argument (toLower(123), trim(true), size(123)) escaped as a raw AttributeError/TypeError instead of evaluating to NULL. ScalarFunctionExpression.evaluate now catches those and returns None, mirroring how ArithmeticExpression already degrades to NULL on incompatible operands.

Added a parametrized regression test in grandcypher/test_scalar_functions.py; it fails on all four cases without the fix and passes with it. Full suite: 504 passed, 2 xfailed.

This change was prepared with AI assistance; the regression test was run locally and fails without the fix.

toLower/toUpper/trim called the underlying str method directly, and size
called len(), so a non-string argument such as toLower(123), trim(true) or
size(123) escaped as a raw AttributeError/TypeError instead of evaluating
to NULL.

ScalarFunctionExpression.evaluate now catches AttributeError/TypeError from
the wrapped function and returns None, matching the way
ArithmeticExpression already degrades to NULL on incompatible operands.

Adds a parametrized regression test in test_scalar_functions.py covering
toLower, toUpper, trim and size with invalid argument types.
@codspeed-hq

codspeed-hq Bot commented Aug 3, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 103 untouched benchmarks


Comparing Sanjays2402:fix/scalar-function-invalid-argument-types (9b12111) with master (7119e39)

Open in CodSpeed

@j6k4m8
j6k4m8 self-requested a review August 4, 2026 17:54
@j6k4m8

j6k4m8 commented Aug 4, 2026

Copy link
Copy Markdown
Member

Great fix, thank you @Sanjays2402 !

@j6k4m8
j6k4m8 merged commit 8272be0 into aplbrain:master Aug 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better handling for argument types in queries

2 participants