From 668f60ba7ec0437b205bb731c47766bcf3a56aa2 Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Fri, 22 Jan 2021 16:32:39 -0800 Subject: [PATCH] fix(load_examples): better fix for load_data (#12702) * fix(load_examples): better fix for load_data * Address changes (cherry picked from commit 9a159b30c4730aefd48a9c7532ae398d8bd9150f) --- superset/datasets/commands/importers/v1/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/superset/datasets/commands/importers/v1/utils.py b/superset/datasets/commands/importers/v1/utils.py index 2aa0c461f011f..73c0ca58a0a14 100644 --- a/superset/datasets/commands/importers/v1/utils.py +++ b/superset/datasets/commands/importers/v1/utils.py @@ -24,6 +24,7 @@ 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: