Compare commits

...

4 Commits

Author SHA1 Message Date
ʈᵃᵢ
dee44e7de6 fix(alerts/reports): misconfigured useEffect hook breaks form validation in prod builds (#12779)
(cherry picked from commit 3ed915146d)
2021-01-26 14:27:14 -08:00
Craig Rueda
a492f27cbc feat: Adding option to set_database_uri CLI command (#12740)
* Adding option to set_database_uri CLI command

* Fixing flag logic

(cherry picked from commit 0fed1e04ef)
2021-01-26 14:27:04 -08:00
Beto Dealmeida
668f60ba7e fix(load_examples): better fix for load_data (#12702)
* fix(load_examples): better fix for load_data

* Address changes

(cherry picked from commit 9a159b30c4)
2021-01-22 16:49:01 -08:00
Rob DiCiuccio
489d341688 fix: Stabilize and deprecate legacy alerts module (#12627)
* Add deprecation notice to superset.tasks.schedules

* Reduce retries and schedule window for alerts

(cherry picked from commit e4ae17def5)
2021-01-21 10:08:23 -08:00
5 changed files with 46 additions and 35 deletions

View File

@@ -992,27 +992,23 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
}, [resource]);
// Validation
useEffect(
() => {
validate();
},
currentAlert
? [
currentAlert.name,
currentAlert.owners,
currentAlert.database,
currentAlert.sql,
currentAlert.validator_config_json,
currentAlert.crontab,
currentAlert.working_timeout,
currentAlert.dashboard,
currentAlert.chart,
contentType,
notificationSettings,
conditionNotNull,
]
: [],
);
const currentAlertSafe = currentAlert || {};
useEffect(() => {
validate();
}, [
currentAlertSafe.name,
currentAlertSafe.owners,
currentAlertSafe.database,
currentAlertSafe.sql,
currentAlertSafe.validator_config_json,
currentAlertSafe.crontab,
currentAlertSafe.working_timeout,
currentAlertSafe.dashboard,
currentAlertSafe.chart,
contentType,
notificationSettings,
conditionNotNull,
]);
// Show/hide
if (isHidden && show) {

View File

@@ -191,9 +191,16 @@ def load_examples(
@superset.command()
@click.option("--database_name", "-d", help="Database name to change")
@click.option("--uri", "-u", help="Database URI to change")
def set_database_uri(database_name: str, uri: str) -> None:
@click.option(
"--skip_create",
"-s",
is_flag=True,
default=False,
help="Create the DB if it doesn't exist",
)
def set_database_uri(database_name: str, uri: str, skip_create: bool) -> None:
"""Updates a database connection URI """
utils.get_or_create_db(database_name, uri)
utils.get_or_create_db(database_name, uri, not skip_create)
@superset.command()

View File

@@ -24,6 +24,7 @@ from typing import Any, Dict
from urllib import request
import pandas as pd
from flask import current_app
from sqlalchemy import BigInteger, Boolean, Date, DateTime, Float, String, Text
from sqlalchemy.orm import Session
from sqlalchemy.sql.visitors import VisitableType
@@ -125,6 +126,7 @@ def import_dataset(
def load_data(
data_uri: str, dataset: SqlaTable, example_database: Database, session: Session
) -> None:
data = request.urlopen(data_uri)
if data_uri.endswith(".gz"):
data = gzip.open(data)
@@ -137,7 +139,9 @@ def load_data(
df[column_name] = pd.to_datetime(df[column_name])
# reuse session when loading data if possible, to make import atomic
if example_database.sqlalchemy_uri == get_example_database().sqlalchemy_uri:
if example_database.sqlalchemy_uri == current_app.config.get(
"SQLALCHEMY_DATABASE_URI"
) or not current_app.config.get("SQLALCHEMY_EXAMPLES_URI"):
logger.info("Loading data inside the import transaction")
connection = session.connection()
else:

View File

@@ -14,8 +14,11 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Utility functions used across Superset"""
"""
DEPRECATION NOTICE: this module is deprecated as of v1.0.0.
It will be removed in future versions of Superset. Please
migrate to the new scheduler: `superset.tasks.scheduler`.
"""
import logging
import time
@@ -535,11 +538,10 @@ def schedule_email_report(
@celery_app.task(
name="alerts.run_query",
bind=True,
soft_time_limit=config["EMAIL_ASYNC_TIME_LIMIT_SEC"],
# TODO: find cause of https://github.com/apache/superset/issues/10530
# and remove retry
autoretry_for=(NoSuchColumnError, ResourceClosedError,),
retry_kwargs={"max_retries": 5},
retry_kwargs={"max_retries": 1},
retry_backoff=True,
)
def schedule_alert_query(
@@ -844,8 +846,8 @@ def schedule_alerts() -> None:
resolution = 0
now = datetime.utcnow()
start_at = now - timedelta(
seconds=3600
) # process any missed tasks in the past hour
seconds=300
) # process any missed tasks in the past few minutes
stop_at = now + timedelta(seconds=1)
with session_scope(nullpool=True) as session:
schedule_window(ScheduleType.alert, start_at, stop_at, resolution, session)

View File

@@ -1095,7 +1095,7 @@ def user_label(user: User) -> Optional[str]:
def get_or_create_db(
database_name: str, sqlalchemy_uri: str, *args: Any, **kwargs: Any
database_name: str, sqlalchemy_uri: str, always_create: Optional[bool] = True
) -> "Database":
from superset import db
from superset.models import core as models
@@ -1104,13 +1104,15 @@ def get_or_create_db(
db.session.query(models.Database).filter_by(database_name=database_name).first()
)
if not database:
if not database and always_create:
logger.info("Creating database reference for %s", database_name)
database = models.Database(database_name=database_name, *args, **kwargs)
database = models.Database(database_name=database_name)
db.session.add(database)
database.set_sqlalchemy_uri(sqlalchemy_uri)
db.session.commit()
if database:
database.set_sqlalchemy_uri(sqlalchemy_uri)
db.session.commit()
return database