-
Notifications
You must be signed in to change notification settings - Fork 17.2k
fix(reports): preserve urlParams in multi-tab report fan-out #39884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EnxDev
wants to merge
4
commits into
master
Choose a base branch
from
enxdev/fix/alerts-reports-filter-time-range-multitab-timeout
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+161
−15
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f9c665f
fix(reports): preserve dashboard_state urlParams in report URL builders
EnxDev 460300c
test(reports): clarify flag-off urlParams test scope
EnxDev 012094a
refactor(reports): extract native_filters urlParams merge into a helper
EnxDev a4dba4f
Merge branch 'master' into enxdev/fix/alerts-reports-filter-time-rang…
EnxDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| import logging | ||
| from collections.abc import Sequence | ||
| from datetime import datetime, timedelta | ||
| from typing import Any, Optional, Union | ||
| from uuid import UUID | ||
|
|
@@ -196,7 +197,7 @@ def create_log(self, error_message: Optional[str] = None) -> None: | |
| db.session.commit() # pylint: disable=consider-using-transaction | ||
| except StaleDataError as ex: | ||
| # Report schedule was modified or deleted by another process | ||
| db.session.rollback() | ||
| db.session.rollback() # pylint: disable=consider-using-transaction | ||
| logger.warning( | ||
| "Report schedule (execution %s) was modified or deleted " | ||
| "during execution. This can occur when a report is deleted " | ||
|
|
@@ -280,6 +281,7 @@ def get_dashboard_urls( | |
| ) | ||
| urls = self._get_tabs_urls( | ||
| anchor_list, | ||
| dashboard_state=dashboard_state, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because |
||
| native_filter_params=native_filter_params, | ||
| user_friendly=user_friendly, | ||
| ) | ||
|
|
@@ -291,12 +293,9 @@ def get_dashboard_urls( | |
| # overwriting — dashboard_state may already have urlParams | ||
| # (e.g. standalone=true) that must be preserved. | ||
| state: DashboardPermalinkState = {**dashboard_state} | ||
| existing_params: list[tuple[str, str]] = state.get("urlParams") or [] | ||
| merged_params: list[list[str]] = [ | ||
| list(p) for p in existing_params if p[0] != "native_filters" | ||
| ] | ||
| merged_params.append(["native_filters", native_filter_params or ""]) | ||
| state["urlParams"] = merged_params # type: ignore[typeddict-item] | ||
| state["urlParams"] = self._merge_native_filters_into_url_params( | ||
| state.get("urlParams"), native_filter_params | ||
| ) | ||
| return [ | ||
| self._get_tab_url( | ||
| state, | ||
|
|
@@ -310,12 +309,17 @@ def get_dashboard_urls( | |
| if filter_warnings: | ||
| self._filter_warnings.extend(filter_warnings) | ||
| if native_filter_params and native_filter_params != "()": | ||
| # Preserve any urlParams from extra.dashboard (e.g. standalone=true) | ||
| # set via API even when ALERT_REPORT_TABS is off — same merge | ||
| # semantics as the protected branch above. | ||
| fallback_state = self._report_schedule.extra.get("dashboard") or {} | ||
| return [ | ||
| self._get_tab_url( | ||
| { | ||
| "urlParams": [ | ||
| ["native_filters", native_filter_params] # type: ignore | ||
| ], | ||
| "urlParams": self._merge_native_filters_into_url_params( | ||
| fallback_state.get("urlParams"), | ||
| native_filter_params, | ||
| ) | ||
| }, | ||
| user_friendly=user_friendly, | ||
| ) | ||
|
|
@@ -353,24 +357,51 @@ def _get_tab_url( | |
| user_friendly=user_friendly, | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def _merge_native_filters_into_url_params( | ||
| existing: Optional[Sequence[Sequence[str]]], | ||
| native_filter_params: Optional[str], | ||
| ) -> list[Sequence[str]]: | ||
| """ | ||
| Merge the report's ``native_filters`` into a permalink's existing | ||
| ``urlParams``, deduping any prior ``native_filters`` entry so the | ||
| report's value wins. All other params (e.g. ``standalone=true``) | ||
| survive in their original order. | ||
| """ | ||
| merged: list[Sequence[str]] = [ | ||
| list(p) for p in (existing or []) if p[0] != "native_filters" | ||
| ] | ||
| merged.append(["native_filters", native_filter_params or ""]) | ||
| return merged | ||
|
|
||
| def _get_tabs_urls( | ||
| self, | ||
| tab_anchors: list[str], | ||
| dashboard_state: Optional[DashboardPermalinkState] = None, | ||
| native_filter_params: Optional[str] = None, | ||
| user_friendly: bool = False, | ||
| ) -> list[str]: | ||
| """ | ||
| Get multple tabs urls | ||
| Get multiple tabs urls. | ||
|
|
||
| Each per-tab permalink merges the report's ``native_filters`` into | ||
| the original ``dashboard_state.urlParams`` (deduping any prior | ||
| ``native_filters`` entry), so params like ``standalone=true`` are | ||
| preserved — matching the precedence rules of the single-tab branch | ||
| in :meth:`get_dashboard_urls`. | ||
| """ | ||
| base_state: DashboardPermalinkState = dashboard_state or {} | ||
| merged_params = self._merge_native_filters_into_url_params( | ||
| base_state.get("urlParams"), native_filter_params | ||
| ) | ||
|
|
||
| return [ | ||
| self._get_tab_url( | ||
| { | ||
| "anchor": tab_anchor, | ||
| "dataMask": None, | ||
| "activeTabs": None, | ||
| "urlParams": [ | ||
| ["native_filters", native_filter_params] # type: ignore | ||
| ], | ||
| "urlParams": merged_params, | ||
| }, | ||
| user_friendly=user_friendly, | ||
| ) | ||
|
|
||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a pre-existing pylint warning on pre-existing code in create_log, I added the disable comment because the pre-commit pylint hook failing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the case then some other pr got merged without ci passing