From 099421770c8b6513d220b8d49333d0b9e7c025a8 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Sat, 26 Feb 2022 07:12:04 +1300 Subject: [PATCH] fix: bump Helm chart release version (#18751) (#18758) Co-authored-by: wiktor2200 --- superset/views/database/forms.py | 17 ++++++++--- superset/views/database/views.py | 33 --------------------- tests/integration_tests/csv_upload_tests.py | 4 +++ 3 files changed, 17 insertions(+), 37 deletions(-) diff --git a/superset/views/database/forms.py b/superset/views/database/forms.py index 354cf4203e308..4cf594c48705e 100644 --- a/superset/views/database/forms.py +++ b/superset/views/database/forms.py @@ -29,7 +29,7 @@ StringField, ) from wtforms.ext.sqlalchemy.fields import QuerySelectField -from wtforms.validators import DataRequired, Length, NumberRange, Optional +from wtforms.validators import DataRequired, Length, NumberRange, Optional, Regexp from superset import app, db, security_manager from superset.forms import ( @@ -94,7 +94,10 @@ class CsvToDatabaseForm(UploadToDatabaseForm): name = StringField( _("Table Name"), description=_("Name of table to be created from csv data."), - validators=[DataRequired()], + validators=[ + DataRequired(), + Regexp(r"^[^\.]+$", message=_("Table name cannot contain a schema")), + ], widget=BS3TextFieldWidget(), ) csv_file = FileField( @@ -245,7 +248,10 @@ class ExcelToDatabaseForm(UploadToDatabaseForm): name = StringField( _("Table Name"), description=_("Name of table to be created from excel data."), - validators=[DataRequired()], + validators=[ + DataRequired(), + Regexp(r"^[^\.]+$", message=_("Table name cannot contain a schema")), + ], widget=BS3TextFieldWidget(), ) excel_file = FileField( @@ -378,7 +384,10 @@ class ColumnarToDatabaseForm(UploadToDatabaseForm): name = StringField( _("Table Name"), description=_("Name of table to be created from columnar data."), - validators=[DataRequired()], + validators=[ + DataRequired(), + Regexp(r"^[^\.]+$", message=_("Table name cannot contain a schema")), + ], widget=BS3TextFieldWidget(), ) columnar_file = MultipleFileField( diff --git a/superset/views/database/views.py b/superset/views/database/views.py index a739a035a1ad0..115d168ed636a 100644 --- a/superset/views/database/views.py +++ b/superset/views/database/views.py @@ -142,17 +142,6 @@ def form_post(self, form: CsvToDatabaseForm) -> Response: flash(message, "danger") return redirect("/csvtodatabaseview/form") - if "." in csv_table.table and csv_table.schema: - message = _( - "You cannot specify a namespace both in the name of the table: " - '"%(csv_table.table)s" and in the schema field: ' - '"%(csv_table.schema)s". Please remove one', - table=csv_table.table, - schema=csv_table.schema, - ) - flash(message, "danger") - return redirect("/csvtodatabaseview/form") - try: df = pd.concat( pd.read_csv( @@ -289,17 +278,6 @@ def form_post(self, form: ExcelToDatabaseForm) -> Response: flash(message, "danger") return redirect("/exceltodatabaseview/form") - if "." in excel_table.table and excel_table.schema: - message = _( - "You cannot specify a namespace both in the name of the table: " - '"%(excel_table.table)s" and in the schema field: ' - '"%(excel_table.schema)s". Please remove one', - table=excel_table.table, - schema=excel_table.schema, - ) - flash(message, "danger") - return redirect("/exceltodatabaseview/form") - uploaded_tmp_file_path = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with dir=app.config["UPLOAD_FOLDER"], suffix=os.path.splitext(form.excel_file.data.filename)[1].lower(), @@ -459,17 +437,6 @@ def form_post( # pylint: disable=too-many-locals flash(message, "danger") return redirect("/columnartodatabaseview/form") - if "." in columnar_table.table and columnar_table.schema: - message = _( - "You cannot specify a namespace both in the name of the table: " - '"%(columnar_table.table)s" and in the schema field: ' - '"%(columnar_table.schema)s". Please remove one', - table=columnar_table.table, - schema=columnar_table.schema, - ) - flash(message, "danger") - return redirect("/columnartodatabaseview/form") - try: chunks = [read(file, **kwargs) for file in files] df = pd.concat(chunks) diff --git a/tests/integration_tests/csv_upload_tests.py b/tests/integration_tests/csv_upload_tests.py index 862a6eadfec60..d5da25c38c115 100644 --- a/tests/integration_tests/csv_upload_tests.py +++ b/tests/integration_tests/csv_upload_tests.py @@ -219,6 +219,10 @@ def test_import_csv_enforced_schema(mock_event_logger): full_table_name = f"admin_database.{CSV_UPLOAD_TABLE_W_SCHEMA}" + # Invalid table name + resp = upload_csv(CSV_FILENAME1, full_table_name) + assert "Table name cannot contain a schema" in resp + # no schema specified, fail upload resp = upload_csv(CSV_FILENAME1, CSV_UPLOAD_TABLE_W_SCHEMA, extra={"schema": None}) assert (