bito-code-review[bot] commented on code in PR #43187: URL: https://github.com/apache/superset/pull/43187#discussion_r3788973599
########## tests/unit_tests/commands/importers/v1/import_tag_savepoint_test.py: ########## @@ -0,0 +1,139 @@ +# 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 patch + +import pytest +import yaml +from pytest_mock import MockerFixture +from sqlalchemy.orm import Query +from sqlalchemy.orm.session import Session + +from superset.commands.importers.v1.utils import import_tag +from superset.extensions import feature_flag_manager +from superset.tags.models import Tag, TaggedObject + +OBJECT_ID = 1 +OBJECT_TYPE = "chart" + +CONTENTS = { + "tags.yaml": yaml.dump( + { + "tags": [ + {"tag_name": "tag_1", "description": "first"}, + {"tag_name": "tag_2", "description": "second"}, + ] + } + ) +} + + [email protected] +def session_with_schema(session: Session) -> Session: + from superset.connectors.sqla.models import SqlaTable + + engine = session.get_bind() + SqlaTable.metadata.create_all(engine) # pylint: disable=no-member + + return session + + +def test_conflicting_tag_does_not_poison_the_session( + session_with_schema: Session, mocker: MockerFixture +) -> None: + """ + A tag that loses a concurrent-insert race must not take the rest of the import + down with it. + + Two importers can both observe that a TaggedObject is absent; the loser's insert + then violates uix_tagged_object. Without a SAVEPOINT around each tag that leaves + the Session in pending-rollback state, so the next statement -- for an unrelated + tag -- fails with PendingRollbackError and the whole import is lost (#42912). + + The race is reproduced by committing the association up front and making the + existence check miss it once, which is exactly what the losing importer sees. + """ + conflicting_tag = Tag(name="tag_1", description="first", type="custom") Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Wrong type passed to Tag</b></div> <div id="fix"> `import_tag` at line 336 passes a bare string `"custom"` to `Tag.type`, but the column is defined as `Column(Enum(TagType))`. Use `TagType.custom` to match the type annotation and other usages like `get_tag()` at models.py:152. </div> </div> <small><i>Code Review Run #9457fb</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]
