Skip to content

Commit

Permalink
fix(pydantic): switch to arbitrary_types_allowed=True
Browse files Browse the repository at this point in the history
while switching to use pydantic v2, old `Extra` configuration
isn't working anymore, and we need to switch it out

Ref: https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.validate_assignment
  • Loading branch information
fruch committed Jan 11, 2025
1 parent 97deff4 commit 050802c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
23 changes: 11 additions & 12 deletions sdcm/kafka/kafka_config.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
from typing import Optional

from pydantic import Field, BaseModel, Extra # pylint: disable=no-name-in-module
from pydantic import Field, BaseModel, ConfigDict # pylint: disable=no-name-in-module

# pylint: disable=too-few-public-methods


class ConnectorConfiguration(BaseModel):
# general options
connector_class: str = Field(alias="connector.class")
topics: Optional[str]
topics: Optional[str] = ''

# scylla-cdc-source-connector options
# see https://github.com/scylladb/scylla-cdc-source-connector?tab=readme-ov-file#configuration
# and https://github.com/scylladb/scylla-cdc-source-connector?tab=readme-ov-file#advanced-administration
scylla_name: Optional[str] = Field(alias="scylla.name")
scylla_table_names: Optional[str] = Field(alias="scylla.table.names")
scylla_user: Optional[str] = Field(alias="scylla.user")
scylla_password: Optional[str] = Field(alias="scylla.password")
scylla_name: Optional[str] = Field(alias="scylla.name", default=None)
scylla_table_names: Optional[str] = Field(alias="scylla.table.names", default=None)
scylla_user: Optional[str] = Field(alias="scylla.user", default=None)
scylla_password: Optional[str] = Field(alias="scylla.password", default=None)

# kafka-connect-scylladb
# see https://github.com/scylladb/kafka-connect-scylladb/blob/master/documentation/CONFIG.md
scylladb_contact_points: Optional[str] = Field(alias="scylladb.contact.points")
scylladb_keyspace: Optional[str] = Field(alias="scylladb.keyspace")
scylladb_username: Optional[str] = Field(alias="scylladb.username")
scylladb_password: Optional[str] = Field(alias="scylladb.password")
scylladb_contact_points: Optional[str] = Field(alias="scylladb.contact.points", default=None)
scylladb_keyspace: Optional[str] = Field(alias="scylladb.keyspace", default=None)
scylladb_username: Optional[str] = Field(alias="scylladb.username", default=None)
scylladb_password: Optional[str] = Field(alias="scylladb.password", default=None)

class Config:
extra = Extra.allow
model_config = ConfigDict(arbitrary_types_allowed=True)


class SctKafkaConfiguration(BaseModel):
Expand Down
5 changes: 2 additions & 3 deletions sdcm/mgmt/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Optional
from pathlib import Path

from pydantic import BaseModel, Extra
from pydantic import BaseModel, ConfigDict

from sdcm.utils.distro import Distro
from sdcm.utils.common import get_sct_root_path
Expand Down Expand Up @@ -179,5 +179,4 @@ class AgentBackupParameters(BaseModel):
transfers: Optional[int] = 2
low_level_retries: Optional[int] = 20

class Config:
extra = Extra.forbid
model_config = ConfigDict(arbitrary_types_allowed=False)
5 changes: 4 additions & 1 deletion sdcm/provision/common/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@

from typing import Union

from pydantic import BaseModel # pylint: disable=no-name-in-module
from pydantic import BaseModel, ConfigDict # pylint: disable=no-name-in-module


OptionalType = type(Union[str, None])


class AttrBuilder(BaseModel):

model_config = ConfigDict(arbitrary_types_allowed=True)

@classmethod
def get_properties(cls):
return [prop for prop in dir(cls) if isinstance(getattr(cls, prop), property) and prop[0] != '_']
Expand Down
5 changes: 2 additions & 3 deletions sdcm/provision/scylla_yaml/scylla_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import logging
import yaml
from pydantic import validator, BaseModel, Extra # pylint: disable=no-name-in-module
from pydantic import validator, BaseModel, ConfigDict # pylint: disable=no-name-in-module

from sdcm.provision.scylla_yaml.auxiliaries import RequestSchedulerOptions, EndPointSnitchType, SeedProvider, \
ServerEncryptionOptions, ClientEncryptionOptions
Expand All @@ -26,8 +26,7 @@

class ScyllaYaml(BaseModel): # pylint: disable=too-few-public-methods,too-many-instance-attributes

class Config: # pylint: disable=too-few-public-methods
extra = Extra.allow
model_config = ConfigDict(arbitrary_types_allowed=True)

broadcast_address: str = None # ""
api_port: int = None # 10000
Expand Down
5 changes: 4 additions & 1 deletion sdcm/sct_provision/aws/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from functools import cached_property
from typing import List, Dict, Tuple

from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict
from sdcm import cluster
from sdcm.provision.aws.instance_parameters import AWSInstanceParams
from sdcm.provision.aws.provisioner import AWSInstanceProvisioner
Expand Down Expand Up @@ -49,6 +49,9 @@ def tags(self) -> Dict[str, str]:


class ClusterBase(BaseModel):

model_config = ConfigDict(arbitrary_types_allowed=True)

params: SCTConfiguration
test_id: str
common_tags: TagsType
Expand Down

0 comments on commit 050802c

Please sign in to comment.