Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use CustomSQLAInterface instead of SQLAInterface#14475

Merged
kaxil merged 3 commits intoapache:v1-10-stablefrom
astronomer:sqla-interface-custom-model-plugins-rule
Feb 27, 2021
Merged

Use CustomSQLAInterface instead of SQLAInterface#14475
kaxil merged 3 commits intoapache:v1-10-stablefrom
astronomer:sqla-interface-custom-model-plugins-rule

Conversation

@drdenzy
Copy link
Contributor

@drdenzy drdenzy commented Feb 26, 2021

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)

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.

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)`
Comment on lines +52 to +54
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"))
Copy link
Member

@kaxil kaxil Feb 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other instance other than datamodel where SQLInterface can be used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check if RBAC has been enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kaxil kaxil added this to the Airflow Upgrade Check - 1.3.0 milestone Feb 27, 2021
@kaxil kaxil merged commit 2fa3774 into apache:v1-10-stable Feb 27, 2021
@kaxil kaxil deleted the sqla-interface-custom-model-plugins-rule branch February 27, 2021 01:29
@github-actions
Copy link

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.

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Feb 27, 2021

if flask_appbuilder_views:
for view_obj in flask_appbuilder_views:
if not isinstance(view_obj.get("view").datamodel, CustomSQLAInterface):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Contributor

@eladkal eladkal Feb 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full tests needed We need to run full set of tests for this PR to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants