Skip to content

Commit

Permalink
FIX: correctly use @model_validator
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Jun 20, 2024
1 parent c318c40 commit 9b2970c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/pwa_pages/project_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import json
import re
import sys
from datetime import datetime
from functools import partial
from pathlib import Path
Expand All @@ -14,6 +15,11 @@

from .repo import Repo, get_repo

if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self


def load_yaml(path: Union[Path, str]) -> dict:
with open(path) as stream:
Expand Down Expand Up @@ -89,11 +95,11 @@ class ProjectInventory(BaseModel):
projects: List[Project]
collaborations: Dict[str, str] = {}

@model_validator(mode="before")
def _check_collaboration_exists(cls, values: dict) -> dict: # noqa: N805
defined_collaborations = set(values["collaborations"])
@model_validator(mode="after")
def _check_collaboration_exists(self) -> Self:
defined_collaborations = set(self.collaborations)
project: Project
for project in values["projects"]:
for project in self.projects:
if project.collaboration is None:
continue
if isinstance(project.collaboration, str):
Expand All @@ -104,7 +110,7 @@ def _check_collaboration_exists(cls, values: dict) -> dict: # noqa: N805
if col not in defined_collaborations:
msg = f"No collaboration defined for {col}"
raise ValueError(msg)
return values
return self


def _create_project_entry(project: Project) -> str:
Expand Down

0 comments on commit 9b2970c

Please sign in to comment.