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 a12a180
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
5 changes: 2 additions & 3 deletions sdcm/kafka/kafka_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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

Expand All @@ -25,8 +25,7 @@ class ConnectorConfiguration(BaseModel):
scylladb_username: Optional[str] = Field(alias="scylladb.username")
scylladb_password: Optional[str] = Field(alias="scylladb.password")

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

0 comments on commit a12a180

Please sign in to comment.