From 855077f04d6a58c9a89989c9f94bd87b1d7c746f Mon Sep 17 00:00:00 2001
From: Tzu-ping Chung <uranusjr@gmail.com>
Date: Tue, 4 Jul 2023 13:45:00 +0800
Subject: [PATCH 1/4] Remove Pydantic limit

---
 setup.cfg | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/setup.cfg b/setup.cfg
index 91d3b86331de0..d5d91d3d8ff6d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -126,9 +126,7 @@ install_requires =
     pendulum>=2.0
     pluggy>=1.0
     psutil>=4.2.0
-    # Limit Pydantic to <2.0.0 because it breaks Kubernetes tests and building providers
-    # This limit should be removed after https://github.com/apache/airflow/issues/32311 is fixed
-    pydantic>=1.10.0,<2.0.0
+    pydantic>=1.10.0
     pygments>=2.0.1
     pyjwt>=2.0.0
     python-daemon>=3.0.0

From f17c6dc4ca4d6df48a1b6cbe2c517d19f7ddfb97 Mon Sep 17 00:00:00 2001
From: Tzu-ping Chung <uranusjr@gmail.com>
Date: Wed, 5 Jul 2023 13:55:51 +0800
Subject: [PATCH 2/4] Force-install Pydantic 2 in CI

This is a temporary measure to work around dependencies pinning
Pydantic to 1.8.x. Will remove this once we fixed all the 2.x
incompatibilities.
---
 Dockerfile                                                     | 3 ++-
 Dockerfile.ci                                                  | 3 ++-
 scripts/docker/install_airflow_dependencies_from_branch_tip.sh | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 35afca6672a77..f89293c5a6f52 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -385,7 +385,8 @@ function install_airflow_dependencies_from_branch_tip() {
     pip install --root-user-action ignore \
       ${ADDITIONAL_PIP_INSTALL_FLAGS} \
       "https://github.com/${AIRFLOW_REPO}/archive/${AIRFLOW_BRANCH}.tar.gz#egg=apache-airflow[${AIRFLOW_EXTRAS}]" \
-      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" || true
+      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" \
+      || pip install 'pydantic>=2' || true
     common::install_pip_version
     pip freeze | grep apache-airflow-providers | xargs pip uninstall --yes 2>/dev/null || true
     set +x
diff --git a/Dockerfile.ci b/Dockerfile.ci
index 6df47d6a8a494..f8cb3da0fc55c 100644
--- a/Dockerfile.ci
+++ b/Dockerfile.ci
@@ -345,7 +345,8 @@ function install_airflow_dependencies_from_branch_tip() {
     pip install --root-user-action ignore \
       ${ADDITIONAL_PIP_INSTALL_FLAGS} \
       "https://github.com/${AIRFLOW_REPO}/archive/${AIRFLOW_BRANCH}.tar.gz#egg=apache-airflow[${AIRFLOW_EXTRAS}]" \
-      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" || true
+      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" \
+      || pip install 'pydantic>=2' || true
     common::install_pip_version
     pip freeze | grep apache-airflow-providers | xargs pip uninstall --yes 2>/dev/null || true
     set +x
diff --git a/scripts/docker/install_airflow_dependencies_from_branch_tip.sh b/scripts/docker/install_airflow_dependencies_from_branch_tip.sh
index 2b58d03950e5b..f2c48c7f5d40f 100644
--- a/scripts/docker/install_airflow_dependencies_from_branch_tip.sh
+++ b/scripts/docker/install_airflow_dependencies_from_branch_tip.sh
@@ -51,7 +51,8 @@ function install_airflow_dependencies_from_branch_tip() {
     pip install --root-user-action ignore \
       ${ADDITIONAL_PIP_INSTALL_FLAGS} \
       "https://github.com/${AIRFLOW_REPO}/archive/${AIRFLOW_BRANCH}.tar.gz#egg=apache-airflow[${AIRFLOW_EXTRAS}]" \
-      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" || true
+      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" \
+      || pip install 'pydantic>=2' || true
     common::install_pip_version
     pip freeze | grep apache-airflow-providers | xargs pip uninstall --yes 2>/dev/null || true
     set +x

From 52228da5114227c296a2c6e9a292954147c4123e Mon Sep 17 00:00:00 2001
From: Tzu-ping Chung <uranusjr@gmail.com>
Date: Thu, 6 Jul 2023 16:20:42 +0800
Subject: [PATCH 3/4] Use base datetime class for Pydantic

---
 airflow/serialization/pydantic/dag_run.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/airflow/serialization/pydantic/dag_run.py b/airflow/serialization/pydantic/dag_run.py
index a5ae6b4a22b52..1e1528eb35641 100644
--- a/airflow/serialization/pydantic/dag_run.py
+++ b/airflow/serialization/pydantic/dag_run.py
@@ -18,7 +18,6 @@
 from datetime import datetime
 from typing import List, Optional
 
-from pendulum import DateTime
 from pydantic import BaseModel as BaseModelPydantic
 
 from airflow.serialization.pydantic.dataset import DatasetEventPydantic
@@ -30,7 +29,7 @@ class DagRunPydantic(BaseModelPydantic):
     id: int
     dag_id: str
     queued_at: Optional[datetime]
-    execution_date: DateTime
+    execution_date: datetime
     start_date: Optional[datetime]
     end_date: Optional[datetime]
     state: str

From a952ea1460cfb0ea47f4b2ca9c40b668d8aacf5e Mon Sep 17 00:00:00 2001
From: Tzu-ping Chung <uranusjr@gmail.com>
Date: Fri, 7 Jul 2023 14:08:43 +0800
Subject: [PATCH 4/4] Revert "Force-install Pydantic 2 in CI"

This reverts commit f17c6dc4ca4d6df48a1b6cbe2c517d19f7ddfb97.
---
 Dockerfile                                                     | 3 +--
 Dockerfile.ci                                                  | 3 +--
 scripts/docker/install_airflow_dependencies_from_branch_tip.sh | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index f89293c5a6f52..35afca6672a77 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -385,8 +385,7 @@ function install_airflow_dependencies_from_branch_tip() {
     pip install --root-user-action ignore \
       ${ADDITIONAL_PIP_INSTALL_FLAGS} \
       "https://github.com/${AIRFLOW_REPO}/archive/${AIRFLOW_BRANCH}.tar.gz#egg=apache-airflow[${AIRFLOW_EXTRAS}]" \
-      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" \
-      || pip install 'pydantic>=2' || true
+      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" || true
     common::install_pip_version
     pip freeze | grep apache-airflow-providers | xargs pip uninstall --yes 2>/dev/null || true
     set +x
diff --git a/Dockerfile.ci b/Dockerfile.ci
index f8cb3da0fc55c..6df47d6a8a494 100644
--- a/Dockerfile.ci
+++ b/Dockerfile.ci
@@ -345,8 +345,7 @@ function install_airflow_dependencies_from_branch_tip() {
     pip install --root-user-action ignore \
       ${ADDITIONAL_PIP_INSTALL_FLAGS} \
       "https://github.com/${AIRFLOW_REPO}/archive/${AIRFLOW_BRANCH}.tar.gz#egg=apache-airflow[${AIRFLOW_EXTRAS}]" \
-      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" \
-      || pip install 'pydantic>=2' || true
+      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" || true
     common::install_pip_version
     pip freeze | grep apache-airflow-providers | xargs pip uninstall --yes 2>/dev/null || true
     set +x
diff --git a/scripts/docker/install_airflow_dependencies_from_branch_tip.sh b/scripts/docker/install_airflow_dependencies_from_branch_tip.sh
index f2c48c7f5d40f..2b58d03950e5b 100644
--- a/scripts/docker/install_airflow_dependencies_from_branch_tip.sh
+++ b/scripts/docker/install_airflow_dependencies_from_branch_tip.sh
@@ -51,8 +51,7 @@ function install_airflow_dependencies_from_branch_tip() {
     pip install --root-user-action ignore \
       ${ADDITIONAL_PIP_INSTALL_FLAGS} \
       "https://github.com/${AIRFLOW_REPO}/archive/${AIRFLOW_BRANCH}.tar.gz#egg=apache-airflow[${AIRFLOW_EXTRAS}]" \
-      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" \
-      || pip install 'pydantic>=2' || true
+      --constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" || true
     common::install_pip_version
     pip freeze | grep apache-airflow-providers | xargs pip uninstall --yes 2>/dev/null || true
     set +x
