codeant-ai-for-open-source[bot] commented on code in PR #42088: URL: https://github.com/apache/superset/pull/42088#discussion_r3590313746
########## tests/unit_tests/migrations/viz/table_v1_v2_test.py: ########## @@ -0,0 +1,223 @@ +# 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 typing import Any + +import pytest + +from superset.migrations.shared.migrate_viz import MigrateTableChart +from tests.unit_tests.migrations.viz.utils import migrate_and_assert + +SOURCE_FORM_DATA: dict[str, Any] = { + "datasource": "1__table", + "any_other_key": "untouched", + "viz_type": "table", + "query_mode": "aggregate", + "groupby": ["name"], + "metrics": ["count"], + "percent_metrics": [], + "all_columns": [], + "row_limit": 1000, + "order_desc": True, + "table_timestamp_format": "smart_date", + "page_length": 20, + "include_search": False, + "show_cell_bars": True, + "align_pn": False, + "color_pn": True, + "allow_rearrange_columns": True, + "allow_render_html": True, +} + +TARGET_FORM_DATA: dict[str, Any] = { + "datasource": "1__table", + "any_other_key": "untouched", + "viz_type": "ag-grid-table", + "query_mode": "aggregate", + "groupby": ["name"], + "metrics": ["count"], + "percent_metrics": [], + "all_columns": [], + "row_limit": 1000, + "order_desc": True, + "table_timestamp_format": "smart_date", + "page_length": 20, + "include_search": False, + "show_cell_bars": True, + "align_pn": False, + "color_pn": True, + "form_data_bak": SOURCE_FORM_DATA, +} + + +def test_migration() -> None: + migrate_and_assert(MigrateTableChart, SOURCE_FORM_DATA, TARGET_FORM_DATA) + + +def test_migration_without_datasource_key_in_params() -> None: + """Some slices don't have a "datasource" key inside params, relying + instead on the datasource_id/datasource_type columns โ that key is + normally injected on the fly by Slice.form_data, which the migration + framework bypasses by reading params directly. upgrade_slice must + synthesize the same "id__type" string from those columns, or + _build_query() raises KeyError('datasource') for charts missing it.""" + from superset.models.slice import Slice + from superset.utils import json + + source: dict[str, Any] = { + k: v for k, v in SOURCE_FORM_DATA.items() if k != "datasource" + } + dumped_form_data = json.dumps(source) Review Comment: **Suggestion:** Add an explicit type annotation to this local variable assignment to satisfy the type-hinting requirement for relevant variables. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> This local variable is introduced in new Python code without an explicit type annotation, so it matches the rule requiring type hints on relevant variables that can be annotated. </details> <details> <summary><b>Rule source ๐ </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a503f53e0cc74c6cb98eb09b8c81399c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a503f53e0cc74c6cb98eb09b8c81399c&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/migrations/viz/table_v1_v2_test.py **Line:** 83:83 **Comment:** *Custom Rule: Add an explicit type annotation to this local variable assignment to satisfy the type-hinting requirement for relevant variables. 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%2F42088&comment_hash=e3c5180e73747b06bf7446a01550d7c6db19cbbd7f89219380f2aebe00a71123&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42088&comment_hash=e3c5180e73747b06bf7446a01550d7c6db19cbbd7f89219380f2aebe00a71123&reaction=dislike'>๐</a> ########## tests/unit_tests/migrations/viz/table_v1_v2_test.py: ########## @@ -0,0 +1,223 @@ +# 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 typing import Any + +import pytest + +from superset.migrations.shared.migrate_viz import MigrateTableChart +from tests.unit_tests.migrations.viz.utils import migrate_and_assert + +SOURCE_FORM_DATA: dict[str, Any] = { + "datasource": "1__table", + "any_other_key": "untouched", + "viz_type": "table", + "query_mode": "aggregate", + "groupby": ["name"], + "metrics": ["count"], + "percent_metrics": [], + "all_columns": [], + "row_limit": 1000, + "order_desc": True, + "table_timestamp_format": "smart_date", + "page_length": 20, + "include_search": False, + "show_cell_bars": True, + "align_pn": False, + "color_pn": True, + "allow_rearrange_columns": True, + "allow_render_html": True, +} + +TARGET_FORM_DATA: dict[str, Any] = { + "datasource": "1__table", + "any_other_key": "untouched", + "viz_type": "ag-grid-table", + "query_mode": "aggregate", + "groupby": ["name"], + "metrics": ["count"], + "percent_metrics": [], + "all_columns": [], + "row_limit": 1000, + "order_desc": True, + "table_timestamp_format": "smart_date", + "page_length": 20, + "include_search": False, + "show_cell_bars": True, + "align_pn": False, + "color_pn": True, + "form_data_bak": SOURCE_FORM_DATA, +} + + +def test_migration() -> None: + migrate_and_assert(MigrateTableChart, SOURCE_FORM_DATA, TARGET_FORM_DATA) + + +def test_migration_without_datasource_key_in_params() -> None: + """Some slices don't have a "datasource" key inside params, relying + instead on the datasource_id/datasource_type columns โ that key is + normally injected on the fly by Slice.form_data, which the migration + framework bypasses by reading params directly. upgrade_slice must + synthesize the same "id__type" string from those columns, or + _build_query() raises KeyError('datasource') for charts missing it.""" + from superset.models.slice import Slice + from superset.utils import json + + source: dict[str, Any] = { + k: v for k, v in SOURCE_FORM_DATA.items() if k != "datasource" + } + dumped_form_data = json.dumps(source) + + slc = Slice( + viz_type=MigrateTableChart.source_viz_type, + datasource_id=1, + datasource_type="table", + params=dumped_form_data, + query_context=f'{{"form_data": {dumped_form_data}, "queries": []}}', + ) + + MigrateTableChart.upgrade_slice(slc) + + assert slc.viz_type == MigrateTableChart.target_viz_type + new_form_data = json.loads(slc.params) Review Comment: **Suggestion:** Add a type annotation to this parsed form-data variable assignment. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> This local variable is newly added and left untyped even though it can be annotated, so it violates the type-hint requirement. </details> <details> <summary><b>Rule source ๐ </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c3674c5a231d48dd88203ec2aa93376d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c3674c5a231d48dd88203ec2aa93376d&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/migrations/viz/table_v1_v2_test.py **Line:** 96:96 **Comment:** *Custom Rule: Add a type annotation to this parsed form-data variable assignment. 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%2F42088&comment_hash=1e275b62f5f99716eaec36dbfd947fd76fc058d7795a43e0b7df8ec86b94bd2d&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42088&comment_hash=1e275b62f5f99716eaec36dbfd947fd76fc058d7795a43e0b7df8ec86b94bd2d&reaction=dislike'>๐</a> ########## tests/unit_tests/migrations/viz/table_v1_v2_test.py: ########## @@ -0,0 +1,223 @@ +# 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 typing import Any + +import pytest + +from superset.migrations.shared.migrate_viz import MigrateTableChart +from tests.unit_tests.migrations.viz.utils import migrate_and_assert + +SOURCE_FORM_DATA: dict[str, Any] = { + "datasource": "1__table", + "any_other_key": "untouched", + "viz_type": "table", + "query_mode": "aggregate", + "groupby": ["name"], + "metrics": ["count"], + "percent_metrics": [], + "all_columns": [], + "row_limit": 1000, + "order_desc": True, + "table_timestamp_format": "smart_date", + "page_length": 20, + "include_search": False, + "show_cell_bars": True, + "align_pn": False, + "color_pn": True, + "allow_rearrange_columns": True, + "allow_render_html": True, +} + +TARGET_FORM_DATA: dict[str, Any] = { + "datasource": "1__table", + "any_other_key": "untouched", + "viz_type": "ag-grid-table", + "query_mode": "aggregate", + "groupby": ["name"], + "metrics": ["count"], + "percent_metrics": [], + "all_columns": [], + "row_limit": 1000, + "order_desc": True, + "table_timestamp_format": "smart_date", + "page_length": 20, + "include_search": False, + "show_cell_bars": True, + "align_pn": False, + "color_pn": True, + "form_data_bak": SOURCE_FORM_DATA, +} + + +def test_migration() -> None: + migrate_and_assert(MigrateTableChart, SOURCE_FORM_DATA, TARGET_FORM_DATA) + + +def test_migration_without_datasource_key_in_params() -> None: + """Some slices don't have a "datasource" key inside params, relying + instead on the datasource_id/datasource_type columns โ that key is + normally injected on the fly by Slice.form_data, which the migration + framework bypasses by reading params directly. upgrade_slice must + synthesize the same "id__type" string from those columns, or + _build_query() raises KeyError('datasource') for charts missing it.""" + from superset.models.slice import Slice + from superset.utils import json + + source: dict[str, Any] = { + k: v for k, v in SOURCE_FORM_DATA.items() if k != "datasource" + } + dumped_form_data = json.dumps(source) + + slc = Slice( + viz_type=MigrateTableChart.source_viz_type, + datasource_id=1, + datasource_type="table", + params=dumped_form_data, + query_context=f'{{"form_data": {dumped_form_data}, "queries": []}}', + ) + + MigrateTableChart.upgrade_slice(slc) + + assert slc.viz_type == MigrateTableChart.target_viz_type + new_form_data = json.loads(slc.params) + assert new_form_data["datasource"] == "1__table" + + +def test_migration_raw_mode() -> None: + source: dict[str, Any] = { + **SOURCE_FORM_DATA, + "query_mode": "raw", + "groupby": [], + "metrics": [], + "all_columns": ["name", "sales"], + } + target: dict[str, Any] = { + **TARGET_FORM_DATA, + "query_mode": "raw", + "groupby": [], + "metrics": [], + "all_columns": ["name", "sales"], + "form_data_bak": source, + } + migrate_and_assert(MigrateTableChart, source, target) + + +def test_migration_page_length_all_maps_to_max() -> None: + """page_length: 0 ('All rows') has no v2 dropdown choice; map to 200, + the max of v2's PAGE_SIZE_OPTIONS, so migrated charts keep showing as + many rows per page as v2 supports.""" + source: dict[str, Any] = {**SOURCE_FORM_DATA, "page_length": 0} + target: dict[str, Any] = { + **TARGET_FORM_DATA, + "page_length": 200, + "form_data_bak": source, + } + migrate_and_assert(MigrateTableChart, source, target) + + +def test_migration_page_length_all_as_string_maps_to_max() -> None: + source: dict[str, Any] = {**SOURCE_FORM_DATA, "page_length": "0"} + target: dict[str, Any] = { + **TARGET_FORM_DATA, + "page_length": 200, + "form_data_bak": source, + } + migrate_and_assert(MigrateTableChart, source, target) + + +def test_migration_percent_metric_calculation_all_records_carries_over() -> None: + """percent_metric_calculation now has a v2 equivalent (control panel + + buildQuery all_records branch), so it should carry over unchanged.""" + source: dict[str, Any] = { + **SOURCE_FORM_DATA, + "percent_metrics": ["sum__sales"], + "percent_metric_calculation": "all_records", + } + target: dict[str, Any] = { + **TARGET_FORM_DATA, + "percent_metrics": ["sum__sales"], + "percent_metric_calculation": "all_records", + "form_data_bak": source, + } + migrate_and_assert(MigrateTableChart, source, target) + + +def test_migration_entire_row_conditional_formatting_carries_over() -> None: + """'entire row' conditional formatting now has a v2 equivalent (control + panel + getCellStyle.ts), so it should carry over unchanged.""" + conditional_formatting = [ Review Comment: **Suggestion:** Add an explicit collection type annotation for this local variable to satisfy the typing rule. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> This list variable is introduced without a type annotation, and it is a relevant variable in new Python code that can be annotated. </details> <details> <summary><b>Rule source ๐ </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=57c9a5de0cf24f95b4c78bd1ff9e9a74&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=57c9a5de0cf24f95b4c78bd1ff9e9a74&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/migrations/viz/table_v1_v2_test.py **Line:** 162:162 **Comment:** *Custom Rule: Add an explicit collection type annotation for this local variable to satisfy the typing rule. 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%2F42088&comment_hash=e87c0f1c23741107f50d38180d69bf8aaafaac218d7a09874b89181667acffd3&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42088&comment_hash=e87c0f1c23741107f50d38180d69bf8aaafaac218d7a09874b89181667acffd3&reaction=dislike'>๐</a> ########## tests/unit_tests/migrations/viz/table_v1_v2_test.py: ########## @@ -0,0 +1,223 @@ +# 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 typing import Any + +import pytest + +from superset.migrations.shared.migrate_viz import MigrateTableChart +from tests.unit_tests.migrations.viz.utils import migrate_and_assert + +SOURCE_FORM_DATA: dict[str, Any] = { + "datasource": "1__table", + "any_other_key": "untouched", + "viz_type": "table", + "query_mode": "aggregate", + "groupby": ["name"], + "metrics": ["count"], + "percent_metrics": [], + "all_columns": [], + "row_limit": 1000, + "order_desc": True, + "table_timestamp_format": "smart_date", + "page_length": 20, + "include_search": False, + "show_cell_bars": True, + "align_pn": False, + "color_pn": True, + "allow_rearrange_columns": True, + "allow_render_html": True, +} + +TARGET_FORM_DATA: dict[str, Any] = { + "datasource": "1__table", + "any_other_key": "untouched", + "viz_type": "ag-grid-table", + "query_mode": "aggregate", + "groupby": ["name"], + "metrics": ["count"], + "percent_metrics": [], + "all_columns": [], + "row_limit": 1000, + "order_desc": True, + "table_timestamp_format": "smart_date", + "page_length": 20, + "include_search": False, + "show_cell_bars": True, + "align_pn": False, + "color_pn": True, + "form_data_bak": SOURCE_FORM_DATA, +} + + +def test_migration() -> None: + migrate_and_assert(MigrateTableChart, SOURCE_FORM_DATA, TARGET_FORM_DATA) + + +def test_migration_without_datasource_key_in_params() -> None: + """Some slices don't have a "datasource" key inside params, relying + instead on the datasource_id/datasource_type columns โ that key is + normally injected on the fly by Slice.form_data, which the migration + framework bypasses by reading params directly. upgrade_slice must + synthesize the same "id__type" string from those columns, or + _build_query() raises KeyError('datasource') for charts missing it.""" + from superset.models.slice import Slice + from superset.utils import json + + source: dict[str, Any] = { + k: v for k, v in SOURCE_FORM_DATA.items() if k != "datasource" + } + dumped_form_data = json.dumps(source) + + slc = Slice( Review Comment: **Suggestion:** Add a concrete type annotation for this variable holding the constructed slice object. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> The slice object is assigned to a new local variable without a type annotation, which is a real omission under the Python type-hint rule for annotatable variables. </details> <details> <summary><b>Rule source ๐ </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=99b5eab5c74246f38bb0af44f3e28347&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=99b5eab5c74246f38bb0af44f3e28347&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/migrations/viz/table_v1_v2_test.py **Line:** 85:85 **Comment:** *Custom Rule: Add a concrete type annotation for this variable holding the constructed slice object. 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%2F42088&comment_hash=cb085522ca8b526197d86eb9ab95f152ae09b632694c7f11da53391878c98f9b&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42088&comment_hash=cb085522ca8b526197d86eb9ab95f152ae09b632694c7f11da53391878c98f9b&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]
