Resolve dynamic date parameters on the backend so scheduled queries can use them - #7809
Open
ekanshul wants to merge 1 commit into
Open
Resolve dynamic date parameters on the backend so scheduled queries can use them#7809ekanshul wants to merge 1 commit into
ekanshul wants to merge 1 commit into
Conversation
Greptile SummaryThis PR resolves supported dynamic date presets in backend parameterized-query paths and synchronizes scheduled queries’ stored hashes with the rendered query text.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| redash/models/parameterized_query.py | Adds schema-aware UTC resolution of supported dynamic date and date-range values before validation and rendering. |
| redash/tasks/queries/maintenance.py | Synchronizes scheduled queries’ stored hashes with their dynamically rendered text before enqueueing. |
| tests/models/test_parameterized_query.py | Covers supported presets, formatting variants, calendar boundaries, validation, and unchanged non-date values. |
| tests/tasks/test_refresh_queries.py | Verifies scheduled dynamic-date rendering and stored-hash synchronization without changing updated_at. |
Sequence Diagram
sequenceDiagram
participant Scheduler
participant ParameterizedQuery
participant QueryRecord
participant Executor
Scheduler->>ParameterizedQuery: Apply stored parameters and schema
ParameterizedQuery->>ParameterizedQuery: Resolve supported dynamic date presets
ParameterizedQuery-->>Scheduler: Concrete rendered query text
Scheduler->>QueryRecord: Synchronize rendered query hash
Scheduler->>Executor: Enqueue rendered query
Executor-->>QueryRecord: Attach matching latest result
Reviews (2): Last reviewed commit: "Resolve dynamic date parameters on the b..." | Re-trigger Greptile
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…an use them
Dynamic date and date range values ("d_last_7_days", "d_now", ...) are only
evaluated by the frontend right before it runs a query. Everything that runs a
query without a browser gets the raw "d_*" string instead: scheduled refreshes
fail parameter validation (logging "Could not enqueue query ... due to
InvalidParameterError" and sending failure e-mails every cycle) and saving the
query logs "Unable to update hash for query ...".
ParameterizedQuery.apply() now resolves those values into the same concrete
values the frontend would send, using the definitions from
client/app/services/parameters/DateParameter.js and DateRangeParameter.js
(evaluated in UTC; weeks start on Sunday like moment's default locale).
Unknown "d_*" values are still rejected by the existing validation.
Because the rendered text of such a query changes from run to run, the hash
stored when the query was last saved doesn't necessarily match the text that
refresh_queries is about to run, and Query.update_latest_result() would leave
the query's latest result untouched. refresh_queries() therefore refreshes the
stored hash right before enqueueing, the same way a save does.
Fixes getredash#7710
Fixes getredash#4514
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ekanshul
force-pushed
the
fix-dynamic-date-parameters
branch
from
September 10, 2026 20:33
149284f to
25edfc2
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.
What type of PR is this?
Description
Fixes #7710 and #4514.
Dynamic date and date range values (
d_last_7_days,d_this_month,d_now, …) are only evaluated by the frontend, right before it runs a query (DateRangeParameter.js, DateParameter.js). Everything that runs a query without a browser gets the rawd_*string instead, so for a query whose parameter defaults to a dynamic value:refresh_queriesfails validation on every cycle (_is_date_range("d_last_7_days")raises, which_validturns intoInvalidParameterError), logsCould not enqueue query N due to InvalidParameterError(...), andtrack_failurebumpsschedule_failuresand sends a failure e-mail each time. The schedule never actually runs (Scheduled query executions fail when a query uses dynamic date range parameters #4514).Unable to update hash for query N because of invalid parameters(Invalid parameters on scheduled query date range #7710).Just accepting the strings in
_is_date_range(as tried in #7710) isn't enough: mustache then renders{{ range.start }}as an empty string andmissing_paramsreportsrange.start.Changes
ParameterizedQuery.apply()now resolves dynamic values into the same concrete values the frontend would send, based on each parameter's type from the schema (YYYY-MM-DD,YYYY-MM-DD HH:mmorYYYY-MM-DD HH:mm:ss, as{start, end}for ranges). The presets mirror the frontend definitions one to one, including the "until now" ranges and calendar periods (weeks start on Sunday, like moment's default locale). Values are evaluated in UTC. Unknownd_*values and presets used on the wrong parameter type are still rejected by the existing validation, and non-date parameters are untouched.refresh_queriesis about to run, andQuery.update_latest_result()would leave the query'slatest_query_datauntouched even though the run succeeded.refresh_queriesnow refreshes the stored hash right before enqueueing (Query.update_query_hash(), the same thing a save does, without touchingupdated_at), so the result is attached through the existing hash match and dashboards and alerts on that query see the fresh data. Editing the query while a run is in flight keeps today's semantics: the hash changes with the edit, so the stale result isn't attached.The presets are resolved wherever the parameter definitions are known: scheduled refreshes, the query hash, and API executions that go through the saved query (
/api/queries/<id>/results)./api/queries/<id>/refreshintentionally builds itsParameterizedQuerywithout the schema (#3383), so it is unchanged. No change to how query hashes are calculated either, so this doesn't conflict with the larger rework proposed in #6960; it makes the existing scheduling path work for these queries in the meantime.How is this tested?
Unit tests (pytest, jest)
Manually
New tests in
tests/models/test_parameterized_query.pycover every preset against a fixednow(including leap-year month boundaries and week boundaries), each datetime format, unknown/mismatched presets and non-date parameters.tests/tasks/test_refresh_queries.py: a scheduled query with ad_last_7_daysdefault is enqueued with the resolved dates, and its stored hash is refreshed to match that text without touchingupdated_at.Full backend suite run in the CI image (
docker compose build … && docker compose run redash tests tests/): 942 passed, 1 skipped.Related Tickets & Documents
#7710, #4514, #6960
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
N/A
🤖 Generated with Claude Code