Skip to content

Commit

Permalink
fix(cache warmup): cache warmup 3.1 upgrade (#28)
Browse files Browse the repository at this point in the history
* fix: Update warm up cache url/permission
* use default system node version in pre-commit config
* fix lint errors
  • Loading branch information
kgopal492 authored May 10, 2024
1 parent f411a75 commit 631299b
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: 'Dependency Review'
uses: actions/dependency-review-action@v2
uses: actions/dependency-review-action@v3
with:
fail-on-severity: high
# compatible/incompatible licenses addressed here: https://www.apache.org/legal/resolved.html
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
default_language_version:
node: system
repos:
- repo: https://github.com/MarcoGorelli/auto-walrus
rev: v0.2.2
Expand Down
8 changes: 1 addition & 7 deletions superset/common/query_context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,7 @@ def processing_time_offsets( # pylint: disable=too-many-locals,too-many-stateme
offset_metrics_df = offset_metrics_df.rename(columns=metrics_mapping)

# 3. set time offset for index
index = (
[
*get_base_axis_labels(query_object.columns),
query_object.granularity,
]
or [DTTM_ALIAS]
)[0]
index = (get_base_axis_labels(query_object.columns) or [DTTM_ALIAS])[0]
if not dataframe_utils.is_datetime_series(offset_metrics_df.get(index)):
raise QueryObjectValidationError(
_(
Expand Down
2 changes: 1 addition & 1 deletion superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ class ExtraRelatedQueryFilters(TypedDict, total=False):

EXTRA_RELATED_QUERY_FILTERS: ExtraRelatedQueryFilters = {}

PINTEREST_MENU_ITEMS: list[PinterestMenuItems] = None
PINTEREST_MENU_ITEMS: list[PinterestMenuItems] | None = None


# Extra dynamic query filters make it possible to limit which objects are shown
Expand Down
12 changes: 6 additions & 6 deletions superset/initialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,7 @@ def configure_middlewares(self) -> None:
"ENABLE_HTTPS_OVERRIDE" in self.config
and self.config["ENABLE_HTTPS_OVERRIDE"]
):
self.superset_app.wsgi_app = ForceHttps( # type: ignore
self.superset_app.wsgi_app
)
self.superset_app.wsgi_app = ForceHttps(self.superset_app.wsgi_app)

if self.config["ENABLE_CHUNK_ENCODING"]:

Expand Down Expand Up @@ -721,14 +719,16 @@ def index(self) -> FlaskResponse:
return redirect("/superset/welcome/")


class ForceHttps:
class ForceHttps: # pylint: disable=too-few-public-methods
"""
wrapper class forces the html schema to be "https"
"""

def __init__(self, app):
def __init__(self, app: Flask) -> None:
self.app = app

def __call__(self, environ, start_response):
def __call__(
self, environ: dict[str, Any], start_response: Callable[..., Any]
) -> Any:
environ["wsgi.url_scheme"] = "https"
return self.app(environ, start_response)
2 changes: 1 addition & 1 deletion superset/tasks/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def fetch_url(data: str, headers: dict[str, str]) -> dict[str, str]:
"""
result = {}
try:
url = get_url_path("Superset.warm_up_cache")
url = get_url_path("ChartRestApi.warm_up_cache")
logger.info("Fetching %s with payload %s", url, data)
req = request.Request(
url, data=bytes(data, "utf-8"), headers=headers, method="PUT"
Expand Down
4 changes: 2 additions & 2 deletions superset/tasks/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def db_tables_cache_warm_up(database_id: str, schema_name: str) -> None:
cache_timeout=database.table_cache_timeout,
)
logger.info(
"Database tables cache warm up succeeded for database_id: %i, schema_name: %s",
"Database tables cache warm up succeeded for database_id: %i, schema_name: %s", # pylint: disable=line-too-long
database_id,
schema_name,
)
except SupersetException as ex:
logger.exception(
"Superset exception for db_tables_cache_warm_up job database_id: %i, schema_name: %s, message: %s",
"Superset exception for db_tables_cache_warm_up job database_id: %i, schema_name: %s, message: %s", # pylint: disable=line-too-long
database_id,
schema_name,
ex.message,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/tasks/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_fetch_url(mock_urlopen, mock_request_cls, base_url):

assert data == result["success"]
mock_request_cls.assert_called_once_with(
"http://base-url/superset/warm_up_cache/",
"http://base-url/api/v1/chart/warm_up_cache",
data=data_encoded,
headers=headers,
method="PUT",
Expand Down

0 comments on commit 631299b

Please sign in to comment.