mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-10-29 09:11:57 +00:00
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:
+15
-1
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user