fix: parse multi-unit duration strings in convert_duration_to_interval#3895
Open
juanuicich wants to merge 1 commit into
Open
fix: parse multi-unit duration strings in convert_duration_to_interval#3895juanuicich wants to merge 1 commit into
juanuicich wants to merge 1 commit into
Conversation
|
@juanuicich is attempting to deploy a commit to the Hatchet Team on Vercel. A member of the Team first needs to authorize it. |
The previous helper inspected only the leading integer and the final unit suffix, so multi-unit Go duration strings such as 42m30s were enforced as roughly 42s. Registration accepts these strings through time.ParseDuration and the engine stores them verbatim, so timeouts silently shrank at enforcement time. The replacement walks the whole string and sums every component. It accepts the units the previous helper supported (ms, s, m, h) plus decimal components and an optional leading sign. Legacy single-unit suffixes d, w, y keep their calendar semantics and are only accepted as the entire input. Invalid input still falls back to 5 minutes. Fixes hatchet-dev#3894
d8dae02 to
7359cbf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
convert_duration_to_interval(duration text)only inspects the leading integer and the final unit suffix. Multi-unit Go duration strings such as42m30stherefore parse as roughly42s. Registration accepts the value throughtime.ParseDurationand the engine stores the original string, so timeouts silently shrink at enforcement time.This PR replaces the helper with one that walks the whole string and sums every component into a single fixed interval.
Fixes #3894
What changed
20260512135156_v1_0_106.sqldoesCREATE OR REPLACE FUNCTION convert_duration_to_interval(duration text).ms,s,m,h), decimal components, and an optional leading sign.d,w,ykeep their prior calendar semantics. They are only accepted as the entire input ('1d','1y'), so mixed forms such as'30s1d'fall through to the standard fallback.5 minutes, matching the live function in20240321215205_v0_17_1.sql.-- +goose Downblock restores the body of that prior migration verbatim.frontend/docs/pages/v1/timeouts.mdxandfrontend/docs/pages/v1/error-handling/timeouts.mdxdescribe the multi-unit, decimal format that the engine now enforces.Behavior changes
1.5hto1hbecausenum_valuewasINT. The new helper returns1h30m, which matches what registration validation already accepted.The fix is engine-side because stored values and other clients can already send multi-unit strings. An SDK-only change would not cover them.
Regression coverage
pkg/repository/duration_test.goadds a database-facing test that runs the migration throughsetupPostgresWithMigration(t).Multi-unit and fractional cases compare seconds via:
Cases:
42sto4211mto6601hto360042m30sto25501h30mto54001h30m5sto54051500msto1.51.5hto5400-1.5hto-54000sto0bad,42,30s1dto300(the5 minutesfallback)Legacy single-unit cases compare interval values directly to confirm calendar semantics are preserved:
1dequals1 day1wequals7 days1yequals12 mons10dequals10 daysGenerated files
task generate-sqlcproduces no diff.convert_duration_to_intervalis not declared in the sqlc schema files, so no query signatures change.Test plan
go test -count=1 ./pkg/repository -run TestConvertDurationToInterval -v: passinggo test -count=1 ./pkg/validator -run TestValidatorDuration -v: passingtask generate-sqlcproduces no diffgofmt -s -lon changed files reports no diff (thetask fmt-gobody)task test: full unit suite, 33 packages with tests, all passtask lint-go:golangci-lint run ./... --config .golangci.ymlreports 170 pre-existing issues, none in files this PR touchestask test-integration:go test -count=1 -tags integration $(go list ./... | grep -v quickstart) -failfastagainstdocker composePostgres + RabbitMQ, all pass