diff --git a/toucan_connectors/adobe_analytics/adobe_analytics_connector.py b/toucan_connectors/adobe_analytics/adobe_analytics_connector.py index b6e07fe70..1411bfc84 100644 --- a/toucan_connectors/adobe_analytics/adobe_analytics_connector.py +++ b/toucan_connectors/adobe_analytics/adobe_analytics_connector.py @@ -3,7 +3,6 @@ import pandas as pd from adobe_analytics import Client, ReportDefinition -from pydantic import ConfigDict, __version__ as pydantic_version from toucan_connectors.toucan_connector import ToucanConnector, ToucanDataSource @@ -43,8 +42,6 @@ def report_definition(self): source=self.source, ) -_PYDANTIC_VERSION_ONE = pydantic_version.startswith("1.") - class AdobeAnalyticsConnector(ToucanConnector): """ @@ -63,6 +60,3 @@ def _retrieve_data(self, data_source: AdobeAnalyticsDataSource) -> pd.DataFrame: df = suites[data_source.suite_id].download(data_source.report_definition) df['suite_id'] = data_source.suite_id return df - - if not _PYDANTIC_VERSION_ONE: - model_config = ConfigDict(arbitrary_types_allowed=True) diff --git a/toucan_connectors/anaplan/anaplan_connector.py b/toucan_connectors/anaplan/anaplan_connector.py index 84f0cbea8..db7a03974 100644 --- a/toucan_connectors/anaplan/anaplan_connector.py +++ b/toucan_connectors/anaplan/anaplan_connector.py @@ -90,7 +90,7 @@ class AnaplanAuthError(AnaplanError): class AnaplanConnector(ToucanConnector): data_source_model: AnaplanDataSource username: str - password: Optional[SecretStr] + password: Optional[SecretStr] = None def _extract_json(self, resp: requests.Response) -> dict: if resp.status_code in (401, 403): diff --git a/toucan_connectors/awsathena/awsathena_connector.py b/toucan_connectors/awsathena/awsathena_connector.py index 66d570cbe..6210575b3 100644 --- a/toucan_connectors/awsathena/awsathena_connector.py +++ b/toucan_connectors/awsathena/awsathena_connector.py @@ -4,7 +4,7 @@ import boto3 import pandas as pd from cached_property import cached_property_with_ttl -from pydantic import Field, SecretStr, constr, create_model +from pydantic import ConfigDict, Field, SecretStr, constr, create_model from toucan_connectors.common import ConnectorStatus, apply_query_parameters, sanitize_query from toucan_connectors.pagination import build_pagination_info @@ -77,10 +77,11 @@ class AwsathenaConnector(ToucanConnector, DiscoverableConnector): aws_access_key_id: str = Field(..., description='Your AWS access key ID') aws_secret_access_key: SecretStr = Field(None, description='Your AWS secret key') region_name: str = Field(..., description='Your AWS region name') - - class Config: - underscore_attrs_are_private = True - keep_untouched = (cached_property_with_ttl,) + # TODO[pydantic]: The following keys were removed: `underscore_attrs_are_private`. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. + model_config = ConfigDict( + underscore_attrs_are_private=True, ignored_types=(cached_property_with_ttl,) + ) def get_session(self) -> boto3.Session: return boto3.Session( diff --git a/toucan_connectors/clickhouse/clickhouse_connector.py b/toucan_connectors/clickhouse/clickhouse_connector.py index efd625b4c..f113d6506 100644 --- a/toucan_connectors/clickhouse/clickhouse_connector.py +++ b/toucan_connectors/clickhouse/clickhouse_connector.py @@ -24,6 +24,8 @@ class ClickhouseDataSource(ToucanDataSource): 'your_table")', ) + # TODO[pydantic]: We need to refactor this class, by creating the `model_config` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. class Config: @staticmethod def schema_extra(schema: Dict[str, Any], model: Type['ClickhouseDataSource']) -> None: diff --git a/toucan_connectors/facebook_ads/facebook_ads_connector.py b/toucan_connectors/facebook_ads/facebook_ads_connector.py index 9bd8b4bbc..d534c45ad 100644 --- a/toucan_connectors/facebook_ads/facebook_ads_connector.py +++ b/toucan_connectors/facebook_ads/facebook_ads_connector.py @@ -78,7 +78,7 @@ def determine_query_params(self) -> Dict[str, str]: class FacebookAdsConnector(ToucanConnector): _auth_flow = 'oauth2' - auth_flow_id: Optional[str] + auth_flow_id: Optional[str] = None _oauth_trigger = 'instance' data_source_model: FacebookAdsDataSource oauth2_version = Field('1', **{'ui.hidden': True}) diff --git a/toucan_connectors/github/github_connector.py b/toucan_connectors/github/github_connector.py index fd85a411b..951b7f4d6 100644 --- a/toucan_connectors/github/github_connector.py +++ b/toucan_connectors/github/github_connector.py @@ -97,7 +97,7 @@ def get_form(cls, connector: 'GithubConnector', current_config, **kwargs): class GithubConnector(ToucanConnector): _auth_flow = 'oauth2' - auth_flow_id: Optional[str] + auth_flow_id: Optional[str] = None data_source_model: GithubDataSource _oauth_trigger = 'instance' _oauth2_connector: OAuth2Connector = PrivateAttr() diff --git a/toucan_connectors/google_adwords/google_adwords_connector.py b/toucan_connectors/google_adwords/google_adwords_connector.py index 7b9704036..0aa980898 100644 --- a/toucan_connectors/google_adwords/google_adwords_connector.py +++ b/toucan_connectors/google_adwords/google_adwords_connector.py @@ -59,6 +59,8 @@ class GoogleAdwordsDataSource(ToucanDataSource): description='Max number of rows to extract, for service extraction only', ) + # TODO[pydantic]: We need to refactor this class, by creating the `model_config` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. class Config: @staticmethod def schema_extra(schema: Dict[str, Any], model: Type['GoogleAdwordsDataSource']) -> None: @@ -79,7 +81,7 @@ def schema_extra(schema: Dict[str, Any], model: Type['GoogleAdwordsDataSource']) class GoogleAdwordsConnector(ToucanConnector): data_source_model: GoogleAdwordsDataSource _auth_flow = 'oauth2' - auth_flow_id: Optional[str] + auth_flow_id: Optional[str] = None developer_token: str = None client_customer_id: str = None _oauth_trigger = 'instance' diff --git a/toucan_connectors/google_analytics/google_analytics_connector.py b/toucan_connectors/google_analytics/google_analytics_connector.py index ed7d5d8d1..45af698e7 100644 --- a/toucan_connectors/google_analytics/google_analytics_connector.py +++ b/toucan_connectors/google_analytics/google_analytics_connector.py @@ -3,7 +3,7 @@ import pandas as pd from apiclient.discovery import build from oauth2client.service_account import ServiceAccountCredentials -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field from toucan_connectors.common import nosql_apply_parameters_to_query from toucan_connectors.google_credentials import GoogleCredentials @@ -24,10 +24,7 @@ class DimensionFilter(BaseModel): operator: str expressions: List[str] = None caseSensitive: bool = False - - class Config: - # TODO `not` param is not implemented - extra = 'allow' + model_config = ConfigDict(extra='allow') class DimensionFilterClause(BaseModel): @@ -43,20 +40,14 @@ class DateRange(BaseModel): class Metric(BaseModel): expression: str alias: str = None - - class Config: - # TODO `metricType` param is not implemented - extra = 'allow' + model_config = ConfigDict(extra='allow') class MetricFilter(BaseModel): metricName: str operator: str comparisonValue: str - - class Config: - # TODO `not` param is not implemented - extra = 'allow' + model_config = ConfigDict(extra='allow') class MetricFilterClause(BaseModel): diff --git a/toucan_connectors/google_big_query/google_big_query_connector.py b/toucan_connectors/google_big_query/google_big_query_connector.py index 8404a7522..55f74c77c 100644 --- a/toucan_connectors/google_big_query/google_big_query_connector.py +++ b/toucan_connectors/google_big_query/google_big_query_connector.py @@ -11,7 +11,7 @@ from google.cloud.bigquery.dbapi import _helpers as bigquery_helpers from google.cloud.bigquery.job import QueryJob from google.oauth2.service_account import Credentials -from pydantic import Field, create_model +from pydantic import ConfigDict, Field, create_model from toucan_connectors.common import sanitize_query from toucan_connectors.google_credentials import GoogleCredentials, get_google_oauth2_credentials @@ -103,10 +103,9 @@ class GoogleBigQueryConnector(ToucanConnector, DiscoverableConnector): 'the Google APIs. For more information, see this ' 'documentation', ) - - class Config: - underscore_attrs_are_private = True - keep_untouched = (cached_property,) + # TODO[pydantic]: The following keys were removed: `underscore_attrs_are_private`. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. + model_config = ConfigDict(underscore_attrs_are_private=True, ignored_types=(cached_property,)) @staticmethod def _get_google_credentials(credentials: GoogleCredentials, scopes: List[str]) -> Credentials: diff --git a/toucan_connectors/google_credentials.py b/toucan_connectors/google_credentials.py index acd93d1f0..a42e80a80 100644 --- a/toucan_connectors/google_credentials.py +++ b/toucan_connectors/google_credentials.py @@ -1,4 +1,4 @@ -from pydantic import BaseModel, Field, HttpUrl, validator +from pydantic import BaseModel, Field, HttpUrl, field_validator CREDENTIALS_INFO_MESSAGE = ( 'This information is provided in your ' @@ -42,7 +42,8 @@ class GoogleCredentials(BaseModel): description=CREDENTIALS_INFO_MESSAGE, ) - @validator('private_key') + @field_validator('private_key') + @classmethod def unescape_break_lines(cls, v): """ `private_key` is a long string like diff --git a/toucan_connectors/google_sheets/google_sheets_connector.py b/toucan_connectors/google_sheets/google_sheets_connector.py index 2e2462f50..7b290937c 100644 --- a/toucan_connectors/google_sheets/google_sheets_connector.py +++ b/toucan_connectors/google_sheets/google_sheets_connector.py @@ -34,6 +34,8 @@ class GoogleSheetsDataSource(ToucanDataSource): True, title='Dates as floats', description='Render Date as Floats or String from the sheet' ) + # TODO[pydantic]: We need to refactor this class, by creating the `model_config` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. class Config: @staticmethod def schema_extra(schema: Dict[str, Any], model: Type['GoogleSheetsDataSource']) -> None: diff --git a/toucan_connectors/google_sheets_2/google_sheets_2_connector.py b/toucan_connectors/google_sheets_2/google_sheets_2_connector.py index 6c39e9fbf..f53c6082d 100644 --- a/toucan_connectors/google_sheets_2/google_sheets_2_connector.py +++ b/toucan_connectors/google_sheets_2/google_sheets_2_connector.py @@ -67,6 +67,8 @@ class GoogleSheets2DataSource(ToucanDataSource): parameters: dict = Field(None, description='Additional URL parameters') parse_dates: List[str] = Field([], title='Dates column', description='Columns to parse as date') + # TODO[pydantic]: We need to refactor this class, by creating the `model_config` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. class Config: @staticmethod def schema_extra(schema: Dict[str, Any], model: Type['GoogleSheets2DataSource']) -> None: @@ -98,7 +100,7 @@ class GoogleSheets2Connector(ToucanConnector): _auth_flow = 'oauth2' _oauth_trigger = 'instance' oauth2_version = Field('1', **{'ui.hidden': True}) - auth_flow_id: Optional[str] + auth_flow_id: Optional[str] = None # TODO: turn into a class property _baseroute = 'https://sheets.googleapis.com/v4/spreadsheets/' diff --git a/toucan_connectors/http_api/http_api_connector.py b/toucan_connectors/http_api/http_api_connector.py index 3606561d9..464a5edbc 100644 --- a/toucan_connectors/http_api/http_api_connector.py +++ b/toucan_connectors/http_api/http_api_connector.py @@ -95,6 +95,8 @@ class HttpAPIDataSource(ToucanDataSource): filter: str = FilterSchema flatten_column: str = Field(None, description='Column containing nested rows') + # TODO[pydantic]: We need to refactor this class, by creating the `model_config` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. class Config: @staticmethod def schema_extra(schema: Dict[str, Any], model: Type['HttpAPIDataSource']) -> None: diff --git a/toucan_connectors/hubspot/hubspot_connector.py b/toucan_connectors/hubspot/hubspot_connector.py index 9125ce0ca..7bd2d45a2 100644 --- a/toucan_connectors/hubspot/hubspot_connector.py +++ b/toucan_connectors/hubspot/hubspot_connector.py @@ -70,7 +70,7 @@ class HubspotDataSource(ToucanDataSource): class HubspotConnector(ToucanConnector): _auth_flow = 'oauth2' - auth_flow_id: Optional[str] + auth_flow_id: Optional[str] = None _oauth_trigger = 'instance' oauth2_version = Field('1', **{'ui.hidden': True}) data_source_model: HubspotDataSource diff --git a/toucan_connectors/hubspot_private_app/hubspot_connector.py b/toucan_connectors/hubspot_private_app/hubspot_connector.py index 81ab3b955..0c32c7597 100644 --- a/toucan_connectors/hubspot_private_app/hubspot_connector.py +++ b/toucan_connectors/hubspot_private_app/hubspot_connector.py @@ -4,7 +4,7 @@ import pandas as pd from hubspot import HubSpot # type:ignore[import] -from pydantic import BaseModel, Field, SecretStr +from pydantic import BaseModel, ConfigDict, Field, SecretStr from toucan_connectors.pagination import build_pagination_info from toucan_connectors.toucan_connector import DataSlice, ToucanConnector, ToucanDataSource @@ -32,15 +32,11 @@ class _HubSpotPaging(BaseModel): class _HubSpotResult(BaseModel): - created_at: datetime | None - updated_at: datetime | None + created_at: datetime | None = None + updated_at: datetime | None = None id_: str = Field(..., alias='id') properties: dict[str, Any] = Field(default_factory=dict) - - # For basic_api objects, properties are in a 'properties' object. For specialized APIs, such as - # owners, they're keys of the root object - class Config: - extra = 'allow' + model_config = ConfigDict(extra='allow') def to_dict(self) -> dict[str, Any]: dict_ = self.dict(by_alias=True) diff --git a/toucan_connectors/linkedinads/linkedinads_connector.py b/toucan_connectors/linkedinads/linkedinads_connector.py index 261c0445a..9e4a13c5b 100644 --- a/toucan_connectors/linkedinads/linkedinads_connector.py +++ b/toucan_connectors/linkedinads/linkedinads_connector.py @@ -73,6 +73,8 @@ class LinkedinadsDataSource(ToucanDataSource): description='See https://docs.microsoft.com/en-us/linkedin/marketing/integrations/ads-reporting/ads-reporting for more information', ) + # TODO[pydantic]: We need to refactor this class, by creating the `model_config` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. class Config: @staticmethod def schema_extra(schema: Dict[str, Any], model: Type['LinkedinadsDataSource']) -> None: @@ -96,7 +98,7 @@ class LinkedinadsConnector(ToucanConnector): _auth_flow = 'oauth2' auth_flow_id: Optional[ str - ] # This ID is generated & provided to the data provider during the oauth authentication process + ] = None # This ID is generated & provided to the data provider during the oauth authentication process _baseroute = 'https://api.linkedin.com/v2/adAnalyticsV2?q=' template: Template = Field( None, diff --git a/toucan_connectors/mongo/mongo_connector.py b/toucan_connectors/mongo/mongo_connector.py index 036b01b4f..0798669ed 100644 --- a/toucan_connectors/mongo/mongo_connector.py +++ b/toucan_connectors/mongo/mongo_connector.py @@ -5,7 +5,7 @@ import pymongo from bson.son import SON from cached_property import cached_property -from pydantic import Field, SecretStr, create_model, validator +from pydantic import ConfigDict, Field, SecretStr, create_model, validator from toucan_connectors.common import ConnectorStatus, nosql_apply_parameters_to_query from toucan_connectors.json_wrapper import JsonWrapper @@ -152,10 +152,10 @@ class MongoConnector(ToucanConnector, VersionableEngineConnector): username: Optional[str] = Field(None, description='Your login username') password: Optional[SecretStr] = Field(None, description='Your login password') ssl: Optional[bool] = Field(None, description='Create the connection to the server using SSL') + model_config = ConfigDict(ignored_types=(cached_property, _lru_cache_wrapper)) - class Config: - keep_untouched = (cached_property, _lru_cache_wrapper) - + # TODO[pydantic]: We couldn't refactor the `validator`, please replace it by `field_validator` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-validators for more information. @validator('password') def password_must_have_a_user(cls, password, values): if password is not None and values['username'] is None: diff --git a/toucan_connectors/mysql/mysql_connector.py b/toucan_connectors/mysql/mysql_connector.py index aa9dea877..7bb734a87 100644 --- a/toucan_connectors/mysql/mysql_connector.py +++ b/toucan_connectors/mysql/mysql_connector.py @@ -7,7 +7,7 @@ import pandas as pd import pymysql from cached_property import cached_property_with_ttl -from pydantic import Field, SecretStr, constr, create_model, validator +from pydantic import ConfigDict, Field, SecretStr, constr, create_model, validator from pymysql.constants import CR, ER from toucan_connectors.common import ConnectorStatus, pandas_read_sql @@ -142,11 +142,14 @@ class MySQLConnector(ToucanConnector, DiscoverableConnector, VersionableEngineCo description='SSL Mode to use to connect to the MySQL server. ' 'Equivalent of the --ssl-mode option of the MySQL client. Must be set in order to use SSL', ) + # TODO[pydantic]: The following keys were removed: `underscore_attrs_are_private`. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. + model_config = ConfigDict( + underscore_attrs_are_private=True, ignored_types=(cached_property_with_ttl,) + ) - class Config: - underscore_attrs_are_private = True - keep_untouched = (cached_property_with_ttl,) - + # TODO[pydantic]: We couldn't refactor the `validator`, please replace it by `field_validator` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-validators for more information. @validator('ssl_key') @classmethod def ssl_key_validator(cls, ssl_key: str, values: dict) -> str: diff --git a/toucan_connectors/one_drive/one_drive_connector.py b/toucan_connectors/one_drive/one_drive_connector.py index 692cda3ab..b253a0249 100755 --- a/toucan_connectors/one_drive/one_drive_connector.py +++ b/toucan_connectors/one_drive/one_drive_connector.py @@ -45,7 +45,7 @@ class OneDriveDataSource(ToucanDataSource): description='Read one sheet or append multiple sheets', placeholder='Enter a sheet or a comma separated list of sheets', ) - range: Optional[str] + range: Optional[str] = None table: Optional[str] = Field( None, Title='Tables', @@ -77,7 +77,7 @@ class OneDriveConnector(ToucanConnector): _auth_flow = 'oauth2' _oauth_trigger = 'connector' oauth2_version = Field('1', **{'ui.hidden': True}) - auth_flow_id: Optional[str] + auth_flow_id: Optional[str] = None authorization_url: str = Field(None, **{'ui.hidden': True}) token_url: str = Field(None, **{'ui.hidden': True}) diff --git a/toucan_connectors/pagination.py b/toucan_connectors/pagination.py index c91dd4ad9..b7cb464ba 100644 --- a/toucan_connectors/pagination.py +++ b/toucan_connectors/pagination.py @@ -10,7 +10,7 @@ class OffsetLimitInfo(BaseModel): """ offset: int - limit: int | None + limit: int | None = None class UnknownSizeDatasetPaginationInfo(BaseModel): @@ -48,8 +48,8 @@ class PaginationInfo(BaseModel): parameters: OffsetLimitInfo pagination_info: UnknownSizeDatasetPaginationInfo | KnownSizeDatasetPaginationInfo - next_page: OffsetLimitInfo | None - previous_page: OffsetLimitInfo | None + next_page: OffsetLimitInfo | None = None + previous_page: OffsetLimitInfo | None = None def build_pagination_info( diff --git a/toucan_connectors/peakina/peakina_connector.py b/toucan_connectors/peakina/peakina_connector.py index 1542fa155..4f8f8b38f 100644 --- a/toucan_connectors/peakina/peakina_connector.py +++ b/toucan_connectors/peakina/peakina_connector.py @@ -2,13 +2,13 @@ import pandas as pd from peakina.datasource import DataSource +from pydantic import ConfigDict from toucan_connectors.toucan_connector import ToucanConnector class PeakinaDataSource(DataSource): - class Config: - extra = 'allow' + model_config = ConfigDict(extra='allow') def __init__(self, **data: Any) -> None: super().__init__(**data) diff --git a/toucan_connectors/redshift/redshift_database_connector.py b/toucan_connectors/redshift/redshift_database_connector.py index 81618ae02..cc81fc199 100644 --- a/toucan_connectors/redshift/redshift_database_connector.py +++ b/toucan_connectors/redshift/redshift_database_connector.py @@ -7,7 +7,7 @@ import pandas as pd import redshift_connector -from pydantic import Field, SecretStr, create_model, root_validator, validator +from pydantic import Field, SecretStr, create_model, field_validator, root_validator from pydantic.types import constr from toucan_connectors.common import ConnectorStatus @@ -144,6 +144,8 @@ class RedshiftConnector(ToucanConnector, DiscoverableConnector): profile: str | None = Field(None, description='AWS profile') region: str | None = Field(None, description='The region in which there is your aws account.') + # TODO[pydantic]: We need to refactor this class, by creating the `model_config` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. class Config: underscore_attrs_are_private = True keep_untouched = (cached_property,) @@ -156,7 +158,8 @@ def schema_extra(schema: dict[str, Any]) -> None: def available_dbs(self) -> list[str]: return self._list_db_names() - @validator('host') + @field_validator('host') + @classmethod def host_validator(cls, v): return re.sub(r'^https?://', '', v) diff --git a/toucan_connectors/salesforce/salesforce_connector.py b/toucan_connectors/salesforce/salesforce_connector.py index afe8c5766..2c78aa8b8 100644 --- a/toucan_connectors/salesforce/salesforce_connector.py +++ b/toucan_connectors/salesforce/salesforce_connector.py @@ -51,7 +51,7 @@ class SalesforceDataSource(ToucanDataSource): class SalesforceConnector(ToucanConnector): _auth_flow = 'oauth2' - auth_flow_id: Optional[str] + auth_flow_id: Optional[str] = None data_source_model: SalesforceDataSource instance_url: str = Field( None, diff --git a/toucan_connectors/snowflake/snowflake_connector.py b/toucan_connectors/snowflake/snowflake_connector.py index 1822f691c..8f3e92488 100644 --- a/toucan_connectors/snowflake/snowflake_connector.py +++ b/toucan_connectors/snowflake/snowflake_connector.py @@ -149,6 +149,8 @@ class SnowflakeConnector(ToucanConnector[SnowflakeDataSource], DiscoverableConne ) category: Category = Field(Category.SNOWFLAKE, title='category', ui={'checkbox': False}) + # TODO[pydantic]: We need to refactor this class, by creating the `model_config` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. class Config: @staticmethod def schema_extra(schema: dict[str, Any], model: Type['SnowflakeConnector']) -> None: diff --git a/toucan_connectors/soap/soap_connector.py b/toucan_connectors/soap/soap_connector.py index 10953c439..ba86c11d5 100644 --- a/toucan_connectors/soap/soap_connector.py +++ b/toucan_connectors/soap/soap_connector.py @@ -20,6 +20,8 @@ class SoapDataSource(ToucanDataSource): ) flatten_column: str = Field(None, description='Column containing nested rows') + # TODO[pydantic]: We need to refactor this class, by creating the `model_config` manually. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. class Config: @staticmethod def schema_extra(schema: Dict[str, Any], model: Type['SoapDataSource']) -> None: diff --git a/toucan_connectors/toucan_connector.py b/toucan_connectors/toucan_connector.py index 2d1c30fa6..16573edd3 100644 --- a/toucan_connectors/toucan_connector.py +++ b/toucan_connectors/toucan_connector.py @@ -12,7 +12,7 @@ import pandas as pd import tenacity as tny -from pydantic import BaseModel, Field, SecretBytes, SecretStr +from pydantic import BaseModel, ConfigDict, Field, SecretBytes, SecretStr from toucan_connectors.common import ( ConnectorStatus, @@ -96,10 +96,7 @@ class ToucanDataSource(BaseModel, Generic[C]): title="Slow Queries' Cache Expiration Time", description='In seconds. Will override the 5min instance default and/or the connector value', ) - - class Config: - extra = 'forbid' - validate_assignment = True + model_config = ConfigDict(extra='forbid', validate_assignment=True) @classmethod def get_form(cls, connector: C, current_config): @@ -284,7 +281,7 @@ class ToucanConnector(BaseModel, Generic[DS], metaclass=ABCMeta): name: str = Field(...) retry_policy: RetryPolicy | None = RetryPolicy() _retry_on: Iterable[Type[BaseException]] = () - type: str | None + type: str | None = None secrets_storage_version: str = Field('1', **_UI_HIDDEN) # type:ignore[pydantic-field] # Default ttl for all connector's queries (overridable at the data_source level) @@ -297,14 +294,16 @@ class ToucanConnector(BaseModel, Generic[DS], metaclass=ABCMeta): # Used to defined the connection identifier: str = Field(None, **_UI_HIDDEN) # type:ignore[pydantic-field] - - class Config: - extra = 'forbid' - validate_assignment = True - json_encoders = { + # TODO[pydantic]: The following keys were removed: `json_encoders`. + # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. + model_config = ConfigDict( + extra='forbid', + validate_assignment=True, + json_encoders={ SecretStr: lambda v: v.get_secret_value(), SecretBytes: lambda v: v.get_secret_value(), - } + }, + ) # type: ignore [typeddict-unknown-key] @classmethod def __init_subclass__(cls):