Repository navigation
fix: roll back session after OAuth2 token refresh flush failure #46363
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
base: master
Are you sure you want to change the base?
Changes from all commits
3276f30
19b63d4
e6d1416
d92153f
8d06e5d
fad86f0
8add51a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ | |
| from datetime import datetime, time, timedelta, timezone | ||
| from decimal import Decimal | ||
| from enum import Enum | ||
| from functools import cache, partial | ||
| from functools import cache, partial, wraps | ||
| from typing import ( | ||
| Any, | ||
| Callable, | ||
|
|
@@ -43,6 +43,7 @@ | |
| Optional, | ||
| TYPE_CHECKING, | ||
| TypedDict, | ||
| TypeVar, | ||
| Union, | ||
| ) | ||
| from zoneinfo import ZoneInfo, ZoneInfoNotFoundError | ||
|
|
@@ -219,6 +220,30 @@ | |
| ) | ||
| from superset.utils.timing_metrics import timed | ||
|
|
||
| _F = TypeVar("_F", bound=Callable[..., Any]) | ||
|
|
||
|
|
||
| def _rolling_back_failed_flush(func: _F) -> _F: | ||
| """ | ||
| Roll back a session deactivated by a failed flush before the error escapes. | ||
|
|
||
| Building a chart query looks up the engine, and an OAuth2 token refresh staged | ||
| by one lookup is flushed by the next ORM read, which can be any lazy load of | ||
| the query builder (the next engine lookup, columns, metrics). The flush | ||
| failure would otherwise leave the request session inactive. | ||
| """ | ||
|
|
||
| @wraps(func) | ||
| def wrapper(self: Any, *args: Any, **kwargs: Any) -> Any: | ||
| # Not via ``self.database``: that relationship can itself be the lazy load | ||
| # that flushes the failing write. | ||
| from superset.models.core import Database | ||
|
|
||
| with Database._rolling_back_failed_flush(): # pylint: disable=protected-access | ||
| return func(self, *args, **kwargs) | ||
|
|
||
| return cast(_F, wrapper) | ||
|
|
||
|
|
||
| class ValidationResultDict(TypedDict): | ||
| """Type for validation result objects returned by validate_expression.""" | ||
|
|
@@ -6963,6 +6988,7 @@ def convert_tbl_column_to_sqla_col( | |
| col = self.make_sqla_column_compatible(col, label) | ||
| return col | ||
|
|
||
| @_rolling_back_failed_flush | ||
|
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. Measured: when SQLExecutor renders a dataset() macro, a failed flush at a lazy load in get_sqla_query is now rolled back here first, so executor.py:718 returns the statement and its parameters instead of base's driver-only message; the compile_sqla_query and get_df guards do the same. |
||
| def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements # noqa: C901 | ||
| self, | ||
| apply_fetch_values_predicate: bool = False, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.