bito-code-review[bot] commented on code in PR #37932: URL: https://github.com/apache/superset/pull/37932#discussion_r2799509799
########## tests/unit_tests/commands/dataset/test_duplicate.py: ########## @@ -0,0 +1,363 @@ +# 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. +from unittest.mock import MagicMock, Mock, patch + +import pytest + +from superset.commands.dataset.duplicate import DuplicateDatasetCommand +from superset.commands.dataset.exceptions import ( + DatasetExistsValidationError, + DatasetInvalidError, + DatasetNotFoundError, +) +from superset.commands.exceptions import DatasourceTypeInvalidError +from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn +from superset.models.core import Database + + +def test_duplicate_dataset_success(): + """Test successful duplication of a virtual dataset.""" + # Create a mock base model (virtual dataset) + mock_base_model = Mock(spec=SqlaTable) + mock_base_model.id = 1 + mock_base_model.database_id = 1 + mock_base_model.table_name = "original_dataset" + mock_base_model.schema = "public" + mock_base_model.catalog = None + mock_base_model.kind = "virtual" + mock_base_model.sql = "SELECT 1 as c" + mock_base_model.template_params = None + mock_base_model.normalize_columns = False + mock_base_model.always_filter_main_dttm = False + mock_base_model.columns = [] + mock_base_model.metrics = [] + + mock_database = Mock(spec=Database) + mock_database.id = 1 + mock_database.get_default_catalog.return_value = None + + with patch( + "superset.commands.dataset.duplicate.DatasetDAO.find_by_id", + return_value=mock_base_model, + ): + with patch( + "superset.commands.dataset.duplicate.db.session.query" + ) as mock_query: + mock_query.return_value.get.return_value = mock_database + with patch( + "superset.commands.dataset.duplicate.DatasetDAO.validate_uniqueness", + return_value=True, + ): + with patch( + "superset.commands.dataset.duplicate.DuplicateDatasetCommand.populate_owners", + return_value=[], + ): + with patch("superset.commands.dataset.duplicate.db.session.add"): + command = DuplicateDatasetCommand( + { + "base_model_id": 1, + "table_name": "duplicated_dataset", + "owners": [], + } + ) + + # Should not raise any errors + command.validate() Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Incomplete duplication test</b></div> <div id="fix"> The test test_duplicate_dataset_success validates that command.validate() passes without errors, but it does not call command.run() or assert on the duplication result. This misses verifying the actual duplication behavior, such as copying attributes from the base model to the new dataset. Per BITO rule [6262], tests should assert the business logic they claim to test. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion # Should not raise any errors command.validate() # Test the actual duplication result = command.run() assert result.table_name == "duplicated_dataset" assert result.database_id == 1 assert result.schema == "public" assert result.kind == "virtual" assert result.sql == "SELECT 1 as c" ```` </div> </details> </div> <small><i>Code Review Run #2d522b</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset/commands/dataset/duplicate.py: ########## @@ -66,6 +66,7 @@ def run(self) -> Model: table = SqlaTable(table_name=table_name, owners=owners) table.database = database table.schema = self._base_model.schema + table.catalog = self._base_model.catalog Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Catalog Resolution Inconsistency</b></div> <div id="fix"> The catalog assignment here uses self._base_model.catalog directly, but in validate, uniqueness checks against the resolved catalog (default if None). This inconsistency means the created table might have catalog=None while validation assumed default, potentially allowing invalid duplicates. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion table.catalog = self._base_model.catalog or database.get_default_catalog() ```` </div> </details> </div> <small><i>Code Review Run #2d522b</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- 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]
