You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/02/26 12:01:09 UTC

[GitHub] [airflow] kaxil commented on a change in pull request #14475: Use CustomSQLAInterface instead of SQLAInterface

kaxil commented on a change in pull request #14475:
URL: https://github.com/apache/airflow/pull/14475#discussion_r583589759



##########
File path: airflow/upgrade/rules/use_customsqlainterface_class_rule.py
##########
@@ -0,0 +1,64 @@
+# 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 airflow.upgrade.rules.base_rule import BaseRule
+
+
+class UseCustomSQLAInterfaceClassRule(BaseRule):
+    title = "Use CustomSQLAInterface instead of SQLAInterface for custom data models."
+
+    description = """\
+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)`
+                  """
+
+    def check(self):
+
+        from airflow.plugins_manager import flask_appbuilder_views
+
+        plugins_with_sqlainterface_data_model_instance = []
+
+        if flask_appbuilder_views:
+            for view_obj in flask_appbuilder_views:
+                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"))

Review comment:
       Is there any other instancee other than `datamodel` where `SQLInterface` can be used?

##########
File path: airflow/upgrade/rules/use_customsqlainterface_class_rule.py
##########
@@ -0,0 +1,64 @@
+# 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 airflow.upgrade.rules.base_rule import BaseRule
+
+
+class UseCustomSQLAInterfaceClassRule(BaseRule):
+    title = "Use CustomSQLAInterface instead of SQLAInterface for custom data models."
+
+    description = """\
+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)`
+                  """
+
+    def check(self):
+
+        from airflow.plugins_manager import flask_appbuilder_views
+
+        plugins_with_sqlainterface_data_model_instance = []
+
+        if flask_appbuilder_views:
+            for view_obj in flask_appbuilder_views:
+                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"))

Review comment:
       Is there any other instance other than `datamodel` where `SQLInterface` can be used?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org