codeant-ai-for-open-source[bot] commented on code in PR #41591: URL: https://github.com/apache/superset/pull/41591#discussion_r3507845720
########## superset/migrations/versions/2026-06-30_00-00_d24e6b0a9c7f_strip_metricsqlexpressions_from_ag_grid_params.py: ########## @@ -0,0 +1,108 @@ +# 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. +"""strip metricSqlExpressions from ag_grid_table params + +Before PR #41555 the AG Grid table plugin leaked ``metricSqlExpressions`` +(a mapping of every datasource metric/column name to its SQL expression) into +``extra_form_data`` on every filter interaction, which was then serialised into +the ``params`` and ``query_context`` columns on save. For datasources with +many metrics this bloated each chart record by hundreds of MB. + +This migration strips the field from existing rows so those records are no +longer loaded eagerly on every dashboard request. + +Revision ID: d24e6b0a9c7f +Revises: a7d3f1b9c2e4 +Create Date: 2026-06-30 00:00:00.000000 + +""" + +from alembic import op +from sqlalchemy import Column, Integer, String, Text +from sqlalchemy.ext.declarative import declarative_base + +from superset import db +from superset.utils import json + +# revision identifiers, used by Alembic. +revision = "d24e6b0a9c7f" +down_revision = "a7d3f1b9c2e4" + +Base = declarative_base() + +_FIELD = "metricSqlExpressions" +_VIZ_TYPE = "ag_grid_table" + + +class Slice(Base): + __tablename__ = "slices" + id = Column(Integer, primary_key=True) + viz_type = Column(String(250)) + params = Column(Text) + query_context = Column(Text) + + +def _strip_params(slc: Slice) -> bool: + """Remove _FIELD from extra_form_data in params. Returns True if changed.""" + if not slc.params: + return False + try: + params = json.loads(slc.params) + except Exception: + return False + + extra = params.get("extra_form_data", {}) + if _FIELD not in extra: + return False + + del extra[_FIELD] + params["extra_form_data"] = extra + slc.params = json.dumps(params) + return True + + +def _strip_query_context(slc: Slice) -> bool: + """Remove _FIELD from query_context.form_data.extra_form_data. Returns True if changed.""" + if not slc.query_context: + return False + try: + qc = json.loads(slc.query_context) + except Exception: + return False Review Comment: **Suggestion:** Use the shared migration JSON-loading helper for `query_context` parsing to keep migration behavior consistent and compatibility-focused. [custom_rule] **Severity Level:** Minor β οΈ <details> <summary><b>Why it matters? π€ </b></summary> The migration utilities provide `try_load_json` for safe JSON loading in migrations, but this code performs manual parsing with a broad exception handler instead. That is the kind of ad hoc logic the shared-utils rule is meant to avoid. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3a7262c3758d4fee985edf894d18e1d2&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=3a7262c3758d4fee985edf894d18e1d2&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/migrations/versions/2026-06-30_00-00_d24e6b0a9c7f_strip_metricsqlexpressions_from_ag_grid_params.py **Line:** 82:85 **Comment:** *Custom Rule: Use the shared migration JSON-loading helper for `query_context` parsing to keep migration behavior consistent and compatibility-focused. 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%2F41591&comment_hash=eca45bbcb14d174e6e55e4b9bfa958634ddd8e4e4b1fc75305df2b66043831ed&reaction=like'>π</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41591&comment_hash=eca45bbcb14d174e6e55e4b9bfa958634ddd8e4e4b1fc75305df2b66043831ed&reaction=dislike'>π</a> ########## superset/migrations/versions/2026-06-30_00-00_d24e6b0a9c7f_strip_metricsqlexpressions_from_ag_grid_params.py: ########## @@ -0,0 +1,108 @@ +# 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. +"""strip metricSqlExpressions from ag_grid_table params + +Before PR #41555 the AG Grid table plugin leaked ``metricSqlExpressions`` +(a mapping of every datasource metric/column name to its SQL expression) into +``extra_form_data`` on every filter interaction, which was then serialised into +the ``params`` and ``query_context`` columns on save. For datasources with +many metrics this bloated each chart record by hundreds of MB. + +This migration strips the field from existing rows so those records are no +longer loaded eagerly on every dashboard request. + +Revision ID: d24e6b0a9c7f +Revises: a7d3f1b9c2e4 +Create Date: 2026-06-30 00:00:00.000000 + +""" + +from alembic import op +from sqlalchemy import Column, Integer, String, Text +from sqlalchemy.ext.declarative import declarative_base + +from superset import db +from superset.utils import json + +# revision identifiers, used by Alembic. +revision = "d24e6b0a9c7f" +down_revision = "a7d3f1b9c2e4" + +Base = declarative_base() + +_FIELD = "metricSqlExpressions" +_VIZ_TYPE = "ag_grid_table" + + +class Slice(Base): + __tablename__ = "slices" + id = Column(Integer, primary_key=True) + viz_type = Column(String(250)) + params = Column(Text) + query_context = Column(Text) + + +def _strip_params(slc: Slice) -> bool: + """Remove _FIELD from extra_form_data in params. Returns True if changed.""" + if not slc.params: + return False + try: + params = json.loads(slc.params) + except Exception: + return False Review Comment: **Suggestion:** Use the shared JSON-loading helper from migration utilities instead of manual JSON parsing with broad exception handling. [custom_rule] **Severity Level:** Minor β οΈ <details> <summary><b>Why it matters? π€ </b></summary> The shared migration utilities include `try_load_json`, which is designed for this exact pattern. Since the migration manually parses JSON with broad exception handling instead of using the helper, this is a real shared-utils violation. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=99daf0584d214a3a8ee1bdf6ebd13614&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=99daf0584d214a3a8ee1bdf6ebd13614&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/migrations/versions/2026-06-30_00-00_d24e6b0a9c7f_strip_metricsqlexpressions_from_ag_grid_params.py **Line:** 63:66 **Comment:** *Custom Rule: Use the shared JSON-loading helper from migration utilities instead of manual JSON parsing with broad exception handling. 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%2F41591&comment_hash=d384a6f681bba7a8d0da9a94cd15ebfe9d665ccbb5c19d1dc668d7c8c5d0a50b&reaction=like'>π</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41591&comment_hash=d384a6f681bba7a8d0da9a94cd15ebfe9d665ccbb5c19d1dc668d7c8c5d0a50b&reaction=dislike'>π</a> ########## superset/migrations/versions/2026-06-30_00-00_d24e6b0a9c7f_strip_metricsqlexpressions_from_ag_grid_params.py: ########## @@ -0,0 +1,108 @@ +# 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. +"""strip metricSqlExpressions from ag_grid_table params + +Before PR #41555 the AG Grid table plugin leaked ``metricSqlExpressions`` +(a mapping of every datasource metric/column name to its SQL expression) into +``extra_form_data`` on every filter interaction, which was then serialised into +the ``params`` and ``query_context`` columns on save. For datasources with +many metrics this bloated each chart record by hundreds of MB. + +This migration strips the field from existing rows so those records are no +longer loaded eagerly on every dashboard request. + +Revision ID: d24e6b0a9c7f +Revises: a7d3f1b9c2e4 +Create Date: 2026-06-30 00:00:00.000000 + +""" + +from alembic import op +from sqlalchemy import Column, Integer, String, Text +from sqlalchemy.ext.declarative import declarative_base + +from superset import db +from superset.utils import json + +# revision identifiers, used by Alembic. +revision = "d24e6b0a9c7f" +down_revision = "a7d3f1b9c2e4" + +Base = declarative_base() + +_FIELD = "metricSqlExpressions" +_VIZ_TYPE = "ag_grid_table" + + +class Slice(Base): + __tablename__ = "slices" + id = Column(Integer, primary_key=True) + viz_type = Column(String(250)) + params = Column(Text) + query_context = Column(Text) + + +def _strip_params(slc: Slice) -> bool: + """Remove _FIELD from extra_form_data in params. Returns True if changed.""" + if not slc.params: + return False + try: + params = json.loads(slc.params) + except Exception: + return False + + extra = params.get("extra_form_data", {}) + if _FIELD not in extra: + return False + + del extra[_FIELD] + params["extra_form_data"] = extra + slc.params = json.dumps(params) + return True + + +def _strip_query_context(slc: Slice) -> bool: + """Remove _FIELD from query_context.form_data.extra_form_data. Returns True if changed.""" + if not slc.query_context: + return False + try: + qc = json.loads(slc.query_context) + except Exception: + return False + + extra = qc.get("form_data", {}).get("extra_form_data", {}) + if _FIELD not in extra: + return False + + del extra[_FIELD] + slc.query_context = json.dumps(qc) + return True + + +def upgrade() -> None: + bind = op.get_bind() + session = db.Session(bind=bind) + + for slc in session.query(Slice).filter(Slice.viz_type == _VIZ_TYPE): + _strip_params(slc) + _strip_query_context(slc) Review Comment: **Suggestion:** Use the shared migration pagination helper instead of iterating directly over a raw ORM query, so the migration follows the projectβs compatibility-safe migration utilities pattern. [custom_rule] **Severity Level:** Minor β οΈ <details> <summary><b>Why it matters? π€ </b></summary> The migration iterates a raw ORM query directly, while the project has a shared compatibility-safe batching helper (`paginated_update`) used in other migrations. This matches the migration-use-shared-utils rule, so the warning is valid. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=76b52f496e4e42beabf8128b6e3ec672&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=76b52f496e4e42beabf8128b6e3ec672&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/migrations/versions/2026-06-30_00-00_d24e6b0a9c7f_strip_metricsqlexpressions_from_ag_grid_params.py **Line:** 96:102 **Comment:** *Custom Rule: Use the shared migration pagination helper instead of iterating directly over a raw ORM query, so the migration follows the projectβs compatibility-safe migration utilities pattern. 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%2F41591&comment_hash=9886b1e954acff101ec51a4e2731a1d37684eedc080eae01c60846c19a36b180&reaction=like'>π</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41591&comment_hash=9886b1e954acff101ec51a4e2731a1d37684eedc080eae01c60846c19a36b180&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]
