Use CustomSQLAInterface instead of SQLAInterface#14475
Use CustomSQLAInterface instead of SQLAInterface#14475kaxil merged 3 commits intoapache:v1-10-stablefrom
Conversation
for custom data models. From Airflow 2.0, if you want to define your own Flask App Builder models you need to use CustomSQLAInterface instead of SQLAInterface. For Non-RBAC replace: `from flask_appbuilder.models.sqla.interface import SQLAInterface` `datamodel = SQLAInterface(your_data_model)` with RBAC (in 1.10): `from airflow.www_rbac.utils import CustomSQLAInterface` `datamodel = CustomSQLAInterface(your_data_model)` and in 2.0: `from airflow.www.utils import CustomSQLAInterface` `datamodel = CustomSQLAInterface(your_data_model)`
| for attr in dir(view_obj.get("view")): | ||
| if type(getattr(view_obj.get("view"), attr)).__name__ == 'SQLAInterface': | ||
| plugins_with_sqlainterface_data_model_instance.append(view_obj.get("name")) |
There was a problem hiding this comment.
Is there any other instance other than datamodel where SQLInterface can be used?
There was a problem hiding this comment.
Should we also check if RBAC has been enabled?
There was a problem hiding this comment.
Just realised datamodel is a required property. https://flask-appbuilder.readthedocs.io/en/latest/quickhowto.html#define-your-views-views-py
That simplifies everything! I will refactor the code now.
|
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
|
|
||
| if flask_appbuilder_views: | ||
| for view_obj in flask_appbuilder_views: | ||
| if not isinstance(view_obj.get("view").datamodel, CustomSQLAInterface): |
There was a problem hiding this comment.
I don't think this conditional is correct. We have SimpleFormView subclasses that don't use a datamodel attribute and it just causes the upgrade script to crash. Nothing I can find in the flask docs or code suggest that having datamodel attribute is required. Therefore I think this should be replaced with the following:
if hasattr(view_obj, "datamodel") and not isinstance(view_obj.get("view").datamodel, CustomSQLAInterface):There was a problem hiding this comment.
There are no more releases to 1.10 / upgrade checker as it's EOL.
If you found a bug then you can disable the specific rule and create your own custom rule with a fix.
for custom data models.
From Airflow 2.0, if you want to define your own Flask App Builder
models you need to use CustomSQLAInterface instead of SQLAInterface.
For Non-RBAC replace:
from flask_appbuilder.models.sqla.interface import SQLAInterfacedatamodel = SQLAInterface(your_data_model)with RBAC (in 1.10):
from airflow.www_rbac.utils import CustomSQLAInterfacedatamodel = CustomSQLAInterface(your_data_model)and in 2.0:
from airflow.www.utils import CustomSQLAInterfacedatamodel = CustomSQLAInterface(your_data_model)related: #13226
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.