bito-code-review[bot] commented on code in PR #38361: URL: https://github.com/apache/superset/pull/38361#discussion_r2878226611
########## superset/migrations/versions/2026-03-02_12-00_a1b2c3d4e5f6_add_granular_export_permissions.py: ########## @@ -0,0 +1,92 @@ +# 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. +"""add granular export permissions + +Revision ID: a1b2c3d4e5f6 +Revises: 4b2a8c9d3e1f +Create Date: 2026-03-02 12:00:00.000000 + +""" + +# revision identifiers, used by Alembic. +revision = "a1b2c3d4e5f6" +down_revision = "4b2a8c9d3e1f" + +from alembic import op # noqa: E402 +from sqlalchemy.exc import SQLAlchemyError # noqa: E402 +from sqlalchemy.orm import Session # noqa: E402 + +from superset.migrations.shared.security_converge import ( # noqa: E402 + add_pvms, + get_reversed_new_pvms, + get_reversed_pvm_map, + migrate_roles, + Pvm, +) + +NEW_PVMS = { + "Superset": ( + "can_export_data", + "can_export_image", + "can_copy_clipboard", + ) +} + +PVM_MAP = { + Pvm("Superset", "can_csv"): ( + Pvm("Superset", "can_export_data"), + Pvm("Superset", "can_export_image"), + Pvm("Superset", "can_copy_clipboard"), + ), +} + + +def do_upgrade(session: Session) -> None: + add_pvms(session, NEW_PVMS) + migrate_roles(session, PVM_MAP) + + +def do_downgrade(session: Session) -> None: + add_pvms(session, get_reversed_new_pvms(PVM_MAP)) + migrate_roles(session, get_reversed_pvm_map(PVM_MAP)) + + +def upgrade(): + bind = op.get_bind() + session = Session(bind=bind) + + do_upgrade(session) + + try: + session.commit() + except SQLAlchemyError as ex: + session.rollback() + raise Exception(f"An error occurred while upgrading permissions: {ex}") from ex + + +def downgrade(): + bind = op.get_bind() + session = Session(bind=bind) + + do_downgrade(session) + + try: + session.commit() + except SQLAlchemyError as ex: + print(f"An error occurred while downgrading permissions: {ex}") + session.rollback() + pass Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Inconsistent error handling in downgrade</b></div> <div id="fix"> The downgrade() function handles SQLAlchemyError by printing a message and continuing, unlike upgrade() which raises an exception. This inconsistency could lead to silent failures during migration rollback. It should raise an exception instead. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion except SQLAlchemyError as ex: session.rollback() raise Exception(f"An error occurred while downgrading permissions: {ex}") from ex ```` </div> </details> </div> <small><i>Code Review Run #24a95c</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]
