Skip to content

Commit

Permalink
fix(load_examples): better fix for load_data (apache#12702)
Browse files Browse the repository at this point in the history
* fix(load_examples): better fix for load_data

* Address changes
  • Loading branch information
betodealmeida authored Jan 23, 2021
1 parent 0f8a62b commit 9a159b3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion superset/datasets/commands/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 9a159b3

Please sign in to comment.