vars: fix re-generate behavior for dependencies of shared vars (#5001)

fixes https://git.clan.lol/clan/clan-core/issues/3791

This fixes multiple issues we had when re-generating shared vars.

Problem 1: shared vars are re-generated for each individual machine instead of just once (see #3791)

Problem 2: When a shared var was re-generated for one machine, dependent vars on other machines did not get re-generated, leading to broken state

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/5001
This commit is contained in:
DavHau
2025-09-02 14:54:24 +00:00
parent 7f68b10611
commit 37a49a14f4
24 changed files with 373 additions and 152 deletions

View File

@@ -1,6 +1,7 @@
import importlib
import logging
import pkgutil
import sys
from collections.abc import Callable
from dataclasses import dataclass
from functools import wraps
@@ -214,6 +215,8 @@ API.register(get_system_file)
for name, func in self._registry.items():
hints = get_type_hints(func)
print("Generating schema for function:", name, file=sys.stderr)
try:
serialized_hints = {
key: type_to_dict(
@@ -236,6 +239,15 @@ API.register(get_system_file)
if ("error" in t["properties"]["status"]["enum"])
)
# TODO: improve error handling in this function
if "oneOf" not in return_type:
msg = (
f"Return type of function '{name}' is not a union type. Expected a union of Success and Error types."
# @DavHau: no idea wy exactly this leads to the "oneOf" ot being present, but this should help
"Hint: When using dataclasses as return types, ensure they don't contain public fields with non-serializable types"
)
raise JSchemaTypeError(msg)
return_type["oneOf"][1] = {"$ref": "#/$defs/error"}
sig = signature(func)