Skip to content

Commit

Permalink
Config changes required for pydantic model updates (#766)
Browse files Browse the repository at this point in the history
* pydantic 2.0 changes fix

* protected namespaces

* linting
  • Loading branch information
Nathanjp91 authored Jan 9, 2024
1 parent e048d80 commit 869a1d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions darwin/future/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def validate_base_url(cls, v: str) -> str:
assert check.netloc, "base_url must contain a domain"
return v

@model_validator(mode="before")
@classmethod
def remove_global(cls, values: dict) -> dict:
def _remove_global(cls, values: dict) -> dict:
if "global" not in values:
return values
global_conf = values["global"]
Expand All @@ -68,12 +67,13 @@ def remove_global(cls, values: dict) -> dict:
@model_validator(mode="before")
@classmethod
def validate_defaults(cls, values: Any) -> Any:
if values["api_key"]:
values = cls._remove_global(values)
if "api_key" in values:
return values
assert values["default_team"] in values["teams"]
team = values["default_team"]
values["api_key"] = values["teams"][team].api_key
values["datasets_dir"] = values["teams"][team].datasets_dir
values["api_key"] = values["teams"][team]["api_key"]
values["datasets_dir"] = values["teams"][team]["datasets_dir"]
return values

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion darwin/future/core/datasets/create_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def create_dataset(api_client: ClientCore, name: str) -> DatasetCore:
},
)
assert isinstance(response, dict)
return DatasetCore(**response)
return DatasetCore.model_validate(response)
2 changes: 1 addition & 1 deletion darwin/future/pydantic_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class DefaultDarwin(BaseModel):
- objects are passed by reference to prevent unnecesary data copying
"""

model_config = ConfigDict(validate_assignment=True)
model_config = ConfigDict(validate_assignment=True, protected_namespaces=())

0 comments on commit 869a1d6

Please sign in to comment.