potiuk commented on code in PR #50960: URL: https://github.com/apache/airflow/pull/50960#discussion_r2128508247
########## providers/fab/tests/unit/fab/conftest.py: ########## @@ -0,0 +1,26 @@ +# 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 __future__ import annotations + +import pytest + + +@pytest.fixture(autouse=True) +def clear_metadata(): + from flask_appbuilder.extensions import db + + db.metadata.clear() Review Comment: If we do not do this we get a lot of errors. My guess is that it comes from the fact that flask_appbuilder session is scoped to "application_context" and Airflow DB sessions are scoped to "local thread" and somehow they override each other's metadata. example here: https://github.com/apache/airflow/actions/runs/15462899926/job/43529356760#step:6:5328 ```python ---------------------------- Captured stdout setup ----------------------------- Please make sure to build the frontend in static/ directory and restart the server [2025-06-05T09:31:35.960+0000] {override.py:897} WARNING - No user yet created, use flask fab command to do it. _ ERROR at setup of TestFabAuthManager.test_get_authorized_dag_ids[PUT-user_permissions5-expected_results5] _ providers/fab/tests/unit/fab/auth_manager/test_fab_auth_manager.py:112: in flask_app app = create_app(enable_plugins=False) providers/fab/src/airflow/providers/fab/www/app.py:99: in create_app init_airflow_session_interface(flask_app) providers/fab/src/airflow/providers/fab/www/extensions/init_session.py:50: in init_airflow_session_interface app.session_interface = AirflowDatabaseSessionInterface( /usr/local/lib/python3.9/site-packages/flask_session/sqlalchemy/sqlalchemy.py:103: in __init__ self.sql_session_model = create_session_model( /usr/local/lib/python3.9/site-packages/flask_session/sqlalchemy/sqlalchemy.py:21: in create_session_model class Session(db.Model): /usr/local/lib/python3.9/site-packages/flask_sqlalchemy/model.py:100: in __init__ super().__init__(name, bases, d, **kwargs) /usr/local/lib/python3.9/site-packages/flask_sqlalchemy/model.py:120: in __init__ super().__init__(name, bases, d, **kwargs) /usr/local/lib/python3.9/site-packages/sqlalchemy/orm/decl_api.py:76: in __init__ _as_declarative(reg, cls, dict_) /usr/local/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:126: in _as_declarative return _MapperConfig.setup_mapping(registry, cls, dict_, None, {}) /usr/local/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:183: in setup_mapping return cfg_cls(registry, cls_, dict_, table, mapper_kw) /usr/local/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:331: in __init__ self._setup_table(table) /usr/local/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:854: in _setup_table table_cls( /usr/local/lib/python3.9/site-packages/flask_sqlalchemy/model.py:147: in __table_cls__ return sa.Table(*args, **kwargs) <string>:2: in __new__ ??? /usr/local/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py:375: in warned return fn(*args, **kwargs) /usr/local/lib/python3.9/site-packages/sqlalchemy/sql/schema.py:596: in __new__ raise exc.InvalidRequestError( E sqlalchemy.exc.InvalidRequestError: Table 'session' is already defined for this MetaData instance. Specify 'extend_existing=True' to redefine options and columns on an existing Table object. ---------------------------- Captured stdout setup ----------------------------- Please make sure to build the frontend in static/ directory and restart the server [2025-06-05T09:31:36.525+0000] {override.py:897} WARNING - No user yet created, use flask fab command to do it. ``` -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org