codeant-ai-for-open-source[bot] commented on code in PR #40860:
URL: https://github.com/apache/superset/pull/40860#discussion_r3407613935
##########
superset/commands/database/exceptions.py:
##########
@@ -118,6 +118,11 @@ class DatabaseUploadFailed(CommandException):
message = _("Database upload file failed")
+class DatabaseUploadFileTooLarge(CommandException):
+ status = 413
+ message = _("Database upload file exceeds the maximum allowed size.")
Review Comment:
**Suggestion:** Add a concise class docstring describing when this exception
is raised to comply with the documentation requirement for newly added classes.
[custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This is a newly added Python class, and it has no docstring in the final
file state.
The custom rule explicitly requires newly added classes to include
docstrings, so the
suggestion identifies a real rule violation.
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8fdf772de36a452985714e41814689b9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=8fdf772de36a452985714e41814689b9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/commands/database/exceptions.py
**Line:** 120:123
**Comment:**
*Custom Rule: Add a concise class docstring describing when this
exception is raised to comply with the documentation requirement for newly
added classes.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=93e65628f46c6ddcfd104174e1cc3edb1742eef0b41cd94aa593513b5a6a3c2d&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=93e65628f46c6ddcfd104174e1cc3edb1742eef0b41cd94aa593513b5a6a3c2d&reaction=dislike'>👎</a>
##########
tests/unit_tests/commands/databases/upload_command_test.py:
##########
@@ -0,0 +1,119 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import io
+from unittest.mock import MagicMock
+
+import pytest
+from pytest_mock import MockerFixture
+from werkzeug.datastructures import FileStorage
+
+from superset.commands.database.exceptions import DatabaseUploadFileTooLarge
+from superset.commands.database.uploaders.base import UploadCommand
+
+
+def _file(contents: bytes) -> FileStorage:
Review Comment:
**Suggestion:** Add a short docstring to this new helper function describing
that it builds a `FileStorage` object from raw bytes. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This is a newly added Python function in the PR and it has no docstring.
The custom rule requires newly added functions to be documented inline, so
the suggestion correctly identifies a real violation.
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6d55c29b0bf5432e9b0968a070bf3482&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6d55c29b0bf5432e9b0968a070bf3482&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/commands/databases/upload_command_test.py
**Line:** 28:28
**Comment:**
*Custom Rule: Add a short docstring to this new helper function
describing that it builds a `FileStorage` object from raw bytes.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=4d0a998ee7574e256fc264ff4f49a762abd3431f0bff297370c535dbb8c96d28&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=4d0a998ee7574e256fc264ff4f49a762abd3431f0bff297370c535dbb8c96d28&reaction=dislike'>👎</a>
##########
tests/unit_tests/commands/databases/upload_command_test.py:
##########
@@ -0,0 +1,119 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import io
+from unittest.mock import MagicMock
+
+import pytest
+from pytest_mock import MockerFixture
+from werkzeug.datastructures import FileStorage
+
+from superset.commands.database.exceptions import DatabaseUploadFileTooLarge
+from superset.commands.database.uploaders.base import UploadCommand
+
+
+def _file(contents: bytes) -> FileStorage:
+ return FileStorage(stream=io.BytesIO(contents), filename="data.bin")
+
+
+def test_file_size_bytes_does_not_consume_stream() -> None:
+ file = _file(b"abcdefghij") # 10 bytes
+ assert UploadCommand._file_size_bytes(file) == 10
+ # the stream is left at its original position so processing still works
+ assert file.stream.read() == b"abcdefghij"
+
+
+def _command(file: FileStorage) -> UploadCommand:
+ # the reader is not exercised by validate(); a stub is sufficient
+ return UploadCommand(
+ model_id=1,
+ table_name="t",
+ file=file,
+ schema=None,
+ reader=MagicMock(),
+ )
+
+
+def _stub_passing_checks(mocker: MockerFixture) -> None:
+ model = mocker.MagicMock()
+ model.db_engine_spec.supports_file_upload = True
+ mocker.patch(
+ "superset.commands.database.uploaders.base.DatabaseDAO.find_by_id",
+ return_value=model,
+ )
+ mocker.patch(
+ "superset.commands.database.uploaders.base.schema_allows_file_upload",
+ return_value=True,
+ )
+
+
+def test_validate_rejects_file_over_limit(
+ app_context: None, mocker: MockerFixture
+) -> None:
+ _stub_passing_checks(mocker)
+ mocker.patch.dict(
+ "superset.commands.database.uploaders.base.current_app.config",
+ {"UPLOAD_MAX_FILE_SIZE_BYTES": 4},
+ )
+ command = _command(_file(b"too many bytes"))
+ with pytest.raises(DatabaseUploadFileTooLarge):
+ command.validate()
+
+
+def test_validate_allows_file_within_limit(
+ app_context: None, mocker: MockerFixture
+) -> None:
Review Comment:
**Suggestion:** Add a short docstring to this test function describing the
success case when file size is within the configured limit. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This newly added test function has no docstring in the final code.
Since the rule applies to newly added Python functions, the suggestion
correctly identifies a real violation.
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8e1708ebdae34e758363d0158719a4da&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=8e1708ebdae34e758363d0158719a4da&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/commands/databases/upload_command_test.py
**Line:** 76:78
**Comment:**
*Custom Rule: Add a short docstring to this test function describing
the success case when file size is within the configured limit.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=c8d5662de68679b8b2c70db0f544a8f3e7e80908552323f1afff98059dc28d5f&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=c8d5662de68679b8b2c70db0f544a8f3e7e80908552323f1afff98059dc28d5f&reaction=dislike'>👎</a>
##########
tests/unit_tests/commands/databases/upload_command_test.py:
##########
@@ -0,0 +1,119 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import io
+from unittest.mock import MagicMock
+
+import pytest
+from pytest_mock import MockerFixture
+from werkzeug.datastructures import FileStorage
+
+from superset.commands.database.exceptions import DatabaseUploadFileTooLarge
+from superset.commands.database.uploaders.base import UploadCommand
+
+
+def _file(contents: bytes) -> FileStorage:
+ return FileStorage(stream=io.BytesIO(contents), filename="data.bin")
+
+
+def test_file_size_bytes_does_not_consume_stream() -> None:
+ file = _file(b"abcdefghij") # 10 bytes
+ assert UploadCommand._file_size_bytes(file) == 10
+ # the stream is left at its original position so processing still works
+ assert file.stream.read() == b"abcdefghij"
+
+
+def _command(file: FileStorage) -> UploadCommand:
+ # the reader is not exercised by validate(); a stub is sufficient
+ return UploadCommand(
+ model_id=1,
+ table_name="t",
+ file=file,
+ schema=None,
+ reader=MagicMock(),
+ )
+
+
+def _stub_passing_checks(mocker: MockerFixture) -> None:
Review Comment:
**Suggestion:** Add a docstring to this setup helper to describe which
dependencies are mocked and why. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This is a newly added function with no docstring in the final file state.
The rule explicitly flags newly added Python functions that omit docstrings,
so the suggestion is valid.
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=bac6575cd8e94accb0ce3811e169f597&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=bac6575cd8e94accb0ce3811e169f597&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/commands/databases/upload_command_test.py
**Line:** 50:50
**Comment:**
*Custom Rule: Add a docstring to this setup helper to describe which
dependencies are mocked and why.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=e78efbaaf4aafe7dd3da85d256bb423dcd5e9c6e3a2e06216db6d8d27627ed64&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=e78efbaaf4aafe7dd3da85d256bb423dcd5e9c6e3a2e06216db6d8d27627ed64&reaction=dislike'>👎</a>
##########
tests/unit_tests/commands/databases/upload_command_test.py:
##########
@@ -0,0 +1,119 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import io
+from unittest.mock import MagicMock
+
+import pytest
+from pytest_mock import MockerFixture
+from werkzeug.datastructures import FileStorage
+
+from superset.commands.database.exceptions import DatabaseUploadFileTooLarge
+from superset.commands.database.uploaders.base import UploadCommand
+
+
+def _file(contents: bytes) -> FileStorage:
+ return FileStorage(stream=io.BytesIO(contents), filename="data.bin")
+
+
+def test_file_size_bytes_does_not_consume_stream() -> None:
+ file = _file(b"abcdefghij") # 10 bytes
+ assert UploadCommand._file_size_bytes(file) == 10
+ # the stream is left at its original position so processing still works
+ assert file.stream.read() == b"abcdefghij"
+
+
+def _command(file: FileStorage) -> UploadCommand:
Review Comment:
**Suggestion:** Add a concise docstring to this helper function explaining
that it creates an `UploadCommand` test instance. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This helper function is newly introduced and does not include a docstring.
That matches the custom rule requiring new Python functions to be documented.
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1597e6fee53b4ef4b19d9d554c5d970f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=1597e6fee53b4ef4b19d9d554c5d970f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/commands/databases/upload_command_test.py
**Line:** 39:39
**Comment:**
*Custom Rule: Add a concise docstring to this helper function
explaining that it creates an `UploadCommand` test instance.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=297c0b051c6feda3f56c1cff74a232748eb3b8974ee332fe4d9e4e632eab0a62&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=297c0b051c6feda3f56c1cff74a232748eb3b8974ee332fe4d9e4e632eab0a62&reaction=dislike'>👎</a>
##########
tests/unit_tests/commands/databases/upload_command_test.py:
##########
@@ -0,0 +1,119 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import io
+from unittest.mock import MagicMock
+
+import pytest
+from pytest_mock import MockerFixture
+from werkzeug.datastructures import FileStorage
+
+from superset.commands.database.exceptions import DatabaseUploadFileTooLarge
+from superset.commands.database.uploaders.base import UploadCommand
+
+
+def _file(contents: bytes) -> FileStorage:
+ return FileStorage(stream=io.BytesIO(contents), filename="data.bin")
+
+
+def test_file_size_bytes_does_not_consume_stream() -> None:
+ file = _file(b"abcdefghij") # 10 bytes
+ assert UploadCommand._file_size_bytes(file) == 10
+ # the stream is left at its original position so processing still works
+ assert file.stream.read() == b"abcdefghij"
+
+
+def _command(file: FileStorage) -> UploadCommand:
+ # the reader is not exercised by validate(); a stub is sufficient
+ return UploadCommand(
+ model_id=1,
+ table_name="t",
+ file=file,
+ schema=None,
+ reader=MagicMock(),
+ )
+
+
+def _stub_passing_checks(mocker: MockerFixture) -> None:
+ model = mocker.MagicMock()
+ model.db_engine_spec.supports_file_upload = True
+ mocker.patch(
+ "superset.commands.database.uploaders.base.DatabaseDAO.find_by_id",
+ return_value=model,
+ )
+ mocker.patch(
+ "superset.commands.database.uploaders.base.schema_allows_file_upload",
+ return_value=True,
+ )
+
+
+def test_validate_rejects_file_over_limit(
+ app_context: None, mocker: MockerFixture
+) -> None:
Review Comment:
**Suggestion:** Add a brief docstring to this test function clarifying the
expected rejection behavior when the configured file-size limit is exceeded.
[custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This is a new Python function added in the PR and it does not have a
docstring. The custom rule requires new functions to include docstrings.
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8522cf24ce504c839aafa9a2b62d7a7f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=8522cf24ce504c839aafa9a2b62d7a7f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/commands/databases/upload_command_test.py
**Line:** 63:65
**Comment:**
*Custom Rule: Add a brief docstring to this test function clarifying
the expected rejection behavior when the configured file-size limit is exceeded.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=fdf717a2fa490e84238aeeb616431870e4a9b886cddf2f8935858be49ba8d442&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40860&comment_hash=fdf717a2fa490e84238aeeb616431870e4a9b886cddf2f8935858be49ba8d442&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]