fix(config): report computed fields as read-only on update (#1454)

PUT /v1/config/{path} answered "does not exist in model" when the
target was a computed field such as eos_device_instruction_entity_ids.
Raise an explicit read-only error instead, so API clients can tell
read-only fields from unknown ones.

Closes #913
This commit is contained in:
YTM-21
2026-10-26 07:16:16 +01:00
committed by GitHub
parent 58b968562e
commit 8f4fa6fe94
4 changed files with 35 additions and 1 deletions
+15 -1
View File
@@ -3,7 +3,7 @@ from typing import Any, Optional
import pandas as pd
import pendulum
import pytest
from pydantic import Field, ValidationError
from pydantic import BaseModel, Field, ValidationError, computed_field
from akkudoktoreos.core.pydantic import (
PydanticBaseModel,
@@ -199,6 +199,20 @@ class TestPydanticModelNestedValueMixin:
with pytest.raises(TypeError):
PydanticModelNestedValueMixin._get_key_types(User, "unknown_field")
def test_get_key_types_for_computed_field(self):
"""Test _get_key_types reports a computed field as read-only."""
class WithComputed(BaseModel):
value: int = 1
@computed_field # type: ignore[prop-decorator]
@property
def doubled(self) -> int:
return self.value * 2
with pytest.raises(TypeError, match="read-only computed field"):
PydanticModelNestedValueMixin._get_key_types(WithComputed, "doubled")
def test_get_key_types_for_instance_raises(self, user_instance):
"""Test _get_key_types raises an error for an instance."""
with pytest.raises(TypeError):