diff --git a/spoolman/api/v1/field.py b/spoolman/api/v1/field.py index 0f1504c..9efcba7 100644 --- a/spoolman/api/v1/field.py +++ b/spoolman/api/v1/field.py @@ -59,7 +59,7 @@ async def update( key: Annotated[str, Path(min_length=1, max_length=64, regex="^[a-z0-9_]+$")], body: ExtraFieldParameters, ) -> Union[list[ExtraField], JSONResponse]: - body_with_key = ExtraField.parse_obj(body.copy(update={"key": key})) + body_with_key = ExtraField.parse_obj(body.copy(update={"key": key, "entity_type": entity_type})) try: await add_or_update_extra_field(db, entity_type, body_with_key) diff --git a/spoolman/extra_fields.py b/spoolman/extra_fields.py index ca003a2..83e5c18 100644 --- a/spoolman/extra_fields.py +++ b/spoolman/extra_fields.py @@ -36,7 +36,6 @@ class ExtraFieldType(Enum): class ExtraFieldParameters(BaseModel): name: str = Field(description="Nice name", min_length=1, max_length=128) unit: Optional[str] = Field(None, description="Unit of the value", min_length=1, max_length=16) - entity_type: EntityType = Field(description="Entity type this field is for") field_type: ExtraFieldType = Field(description="Type of the field") default_value: Optional[str] = Field(None, description="Default value of the field") choices: Optional[list[str]] = Field(None, description="Choices for the field, only for field type choice") @@ -45,6 +44,7 @@ class ExtraFieldParameters(BaseModel): class ExtraField(ExtraFieldParameters): key: str = Field(description="Unique key", regex="^[a-z0-9_]+$", min_length=1, max_length=64) + entity_type: EntityType = Field(description="Entity type this field is for") def validate_extra_field_value(field: ExtraFieldParameters, value: str) -> None: # noqa: C901, PLR0912