From 6dea72949b091367b13af99a0e2309717280a165 Mon Sep 17 00:00:00 2001 From: sha174n <105581038+sha174n@users.noreply.github.com> Date: Mon, 27 Jan 2025 23:52:05 +0000 Subject: [PATCH] refactor: Remove CSV upload size limit and related validation (#32000) --- superset/config.py | 3 --- superset/databases/schemas.py | 11 ----------- tests/unit_tests/databases/api_test.py | 26 -------------------------- 3 files changed, 40 deletions(-) diff --git a/superset/config.py b/superset/config.py index 02b0d7ef3c6a9..7c1436bb50502 100644 --- a/superset/config.py +++ b/superset/config.py @@ -849,9 +849,6 @@ class D3TimeFormat(TypedDict, total=False): COLUMNAR_EXTENSIONS = {"parquet", "zip"} ALLOWED_EXTENSIONS = {*EXCEL_EXTENSIONS, *CSV_EXTENSIONS, *COLUMNAR_EXTENSIONS} -# Optional maximum file size in bytes when uploading a CSV -CSV_UPLOAD_MAX_SIZE = None - # CSV Options: key/value pairs that will be passed as argument to DataFrame.to_csv # method. # note: index option should not be overridden diff --git a/superset/databases/schemas.py b/superset/databases/schemas.py index 0c821a6f34d46..66366d95199a8 100644 --- a/superset/databases/schemas.py +++ b/superset/databases/schemas.py @@ -20,7 +20,6 @@ from __future__ import annotations import inspect -import os from pathlib import Path from typing import Any, TypedDict @@ -1234,16 +1233,6 @@ def convert_column_data_types( ) from ex return data - @validates("file") - def validate_file_size(self, file: FileStorage) -> None: - file.flush() - size = os.fstat(file.fileno()).st_size - if ( - current_app.config["CSV_UPLOAD_MAX_SIZE"] is not None - and size > current_app.config["CSV_UPLOAD_MAX_SIZE"] - ): - raise ValidationError([_("File size exceeds the maximum allowed size.")]) - class ExcelUploadPostSchema(BaseUploadPostSchema): """ diff --git a/tests/unit_tests/databases/api_test.py b/tests/unit_tests/databases/api_test.py index e24580cb8ac3e..be835cb877805 100644 --- a/tests/unit_tests/databases/api_test.py +++ b/tests/unit_tests/databases/api_test.py @@ -1090,32 +1090,6 @@ def test_csv_upload_validation( assert response.json == expected_response -def test_csv_upload_file_size_validation( - mocker: MockerFixture, - client: Any, - full_api_access: None, -) -> None: - """ - Test CSV Upload validation fails. - """ - _ = mocker.patch.object(UploadCommand, "run") - current_app.config["CSV_UPLOAD_MAX_SIZE"] = 5 - response = client.post( - "/api/v1/database/1/csv_upload/", - data={ - "file": (create_csv_file(), "out.csv"), - "table_name": "table1", - "delimiter": ",", - }, - content_type="multipart/form-data", - ) - assert response.status_code == 400 - assert response.json == { - "message": {"file": ["File size exceeds the maximum allowed size."]} - } - current_app.config["CSV_UPLOAD_MAX_SIZE"] = None - - @pytest.mark.parametrize( "filename", [