You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query failing with "negative substring length not allowed" #55
That's an error coming back from Postgres. To figure it out, we'd need to run the query in the Hasura console and use the analyze button to get the actual Postgres query being run, then figure out where the error is actually happening.
I'd guess it's because you're filtering by redeem_bytecode_pattern, which is itself a computed property. So if the other conditions take your limit 1 query down to 0, it's running that function on nothing, and somewhere inside there it "works" until a substring function is called with a negative integer.
I'd guess redeem_bytecode_pattern just needs to return early before doing the invalid operation. I can't prioritize figuring this out myself, but I'd be happy to take a PR!
Thing is, other conditions don't limit it to 0. For example if you change to limit: 2 then it returns a proper result.
If you change the block height range to something that hasn't been mined yet, then you get a proper empty array as result, with both limit: 1 and limit: 2.
Also, this one which selects only 1 block trips with the same error. Change _gte and _lt heights +1 and it returns empty array proper. Commenting out the redeem_bytecode_pattern makes it return empty array, so I suspect some bug there.
However, the queries searching by unlocking_bytecode_pattern are still unusable as they scan the entire input dataset and fail to complete in statement_timeout timespan. I am not sure if it is possible to add an index for a computed field. But it could be meaningful to materialize this field as a column.
Activity
bitjson commentedon Feb 24, 2023
Thanks for opening an issue! On the demo instance, that returns:
{ "errors": [ { "extensions": { "code": "data-exception", "path": "$" }, "message": "negative substring length not allowed" } ] }That's an error coming back from Postgres. To figure it out, we'd need to run the query in the Hasura console and use the
analyzebutton to get the actual Postgres query being run, then figure out where the error is actually happening.I'd guess it's because you're filtering by
redeem_bytecode_pattern, which is itself a computed property. So if the other conditions take your limit 1 query down to 0, it's running that function on nothing, and somewhere inside there it "works" until a substring function is called with a negative integer.I'd guess
redeem_bytecode_patternjust needs to return early before doing the invalid operation. I can't prioritize figuring this out myself, but I'd be happy to take a PR!A60AB5450353F40E commentedon Feb 24, 2023
Thing is, other conditions don't limit it to 0. For example if you change to
limit: 2then it returns a proper result.If you change the block height range to something that hasn't been mined yet, then you get a proper empty array as result, with both
limit: 1andlimit: 2.A60AB5450353F40E commentedon Mar 1, 2023
Also, this one which selects only 1 block trips with the same error. Change _gte and _lt heights +1 and it returns empty array proper. Commenting out the
redeem_bytecode_patternmakes it return empty array, so I suspect some bug there.A60AB5450353F40E commentedon Mar 27, 2023
Replacing regex with like fails on some blocks, too:
Query
Result
mainnet-pat commentedon Apr 6, 2025
#70 Fixes this issue.
However, the queries searching by unlocking_bytecode_pattern are still unusable as they scan the entire input dataset and fail to complete in
statement_timeouttimespan. I am not sure if it is possible to add an index for a computed field. But it could be meaningful to materialize this field as a column.fix(sql): harden redeem bytecode parser (fixes bitauth#75 item 7, fixes