From b2bee15ca7897aa570c164be744ce278db08916a Mon Sep 17 00:00:00 2001 From: Giorgio Basile Date: Mon, 16 Oct 2023 17:14:59 +0200 Subject: [PATCH] Fix pydantic import to handle v2 --- CHANGELOG.md | 2 ++ prefect_planetary_computer/credentials.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15f17b8..c874a46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fix pydantic imports to handle v2 support from Prefect - [#26](https://github.com/giorgiobasile/prefect-planetary-computer/pull/26) + ### Security ## 0.1.0 diff --git a/prefect_planetary_computer/credentials.py b/prefect_planetary_computer/credentials.py index 7253972..eba5271 100644 --- a/prefect_planetary_computer/credentials.py +++ b/prefect_planetary_computer/credentials.py @@ -8,7 +8,7 @@ from dask_gateway.auth import JupyterHubAuth from prefect.blocks.core import Block from prefect_dask import DaskTaskRunner -from pydantic import Field, SecretStr +from pydantic import VERSION as PYDANTIC_VERSION from prefect_planetary_computer.constants import ( CATALOG_URL, @@ -16,6 +16,11 @@ GATEWAY_PROXY_ADDRESS, ) +if PYDANTIC_VERSION.startswith("2."): + from pydantic.v1 import Field, SecretStr +else: + from pydantic import Field, SecretStr + class PlanetaryComputerCredentials(Block): """ @@ -27,8 +32,8 @@ class PlanetaryComputerCredentials(Block): to instantiate clusters through Dask Gateway. Args: - subscription_key (str): A subscription key to access the full PC data catalog. - hub_api_token (str): The JupyterHub API token to instantiate clusters through Dask Gateway. + subscription_key (str, optional): A subscription key to access the full PC data catalog. + hub_api_token (str, optional): The JupyterHub API token to instantiate clusters through Dask Gateway. Example: Load stored Planetary Computer credentials: