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 2020/12/23 07:36:58 UTC

[GitHub] [airflow] houqp commented on a change in pull request #13278: fix dag run type enum query for mysqldb driver

houqp commented on a change in pull request #13278:
URL: https://github.com/apache/airflow/pull/13278#discussion_r547757953



##########
File path: airflow/utils/types.py
##########
@@ -16,8 +16,31 @@
 # under the License.
 import enum
 
+from sqlalchemy.types import TypeDecorator, String
 
-class DagRunType(str, enum.Enum):
+
+class EnumString(TypeDecorator):
+    """
+    Declare db column with this type to make the column compatible with string
+    and string based enum values when building the sqlalchemy ORM query. It can
+    be used just like sqlalchemy.types.String, for example:
+
+    ```
+    class Table(Base):
+        __tablename__ = "t"
+        run_type = Column(EnumString(50), nullable=False)
+    ```
+    """
+    impl = String
+
+    def process_bind_param(self, value, dialect):
+        if isinstance(value, enum.Enum):
+            return value.value
+        else:
+            return value
+
+
+class DagRunType(enum.Enum):

Review comment:
       @ashb i removed the str here to avoid this type being misused in the rest of the code base. For example, if `DagRunType.SCHEDULED` is used for column types that are not declared as `EnumString`, developer will get the incorrect behavior regardless of which db driver is being used, so we can surface the issue sooner. That way, it's less likely to get half working PR merged into master.




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