Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/properties.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Note that the constraints for functional properties are set by assigning a dicti
.. note::

Currently, property values are not validated when they are set directly in Python, only via HTTP.
Setting ``validate_properties_on_set = True`` in `~lt.Thing._class_settings` enables validation when they are set in Python. This may become default behaviour in the future.
Setting ``validate_properties_on_set = True`` in `~lt.Thing._class_settings` enables validation when they are set in Python. This will become default behaviour in the future.

Property metadata
-----------------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/public_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ This page summarises the parts of the LabThings API that should be most frequent
Whether properties should be validated against their model when set from Python.
Properties are always validated when set over HTTP.
By default, no validation is performed when they are set from Python.
Setting this key to `True` will enable validation: this is likely to become the default in the future.
Setting this key to `True` will enable validation: this will become the default in the future.


.. py:class:: ThingConfig(/, **data: Any)
Expand Down
14 changes: 8 additions & 6 deletions src/labthings_fastapi/thing_class_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ def get_validate_properties_on_set(cls: "type[Thing]") -> bool:
:return: whether validation should be performed.
"""
settings = get_class_settings(cls)
if "validate_properties_on_set" not in settings:
value = settings.get(
"validate_properties_on_set",
False,
)
if not value:
warnings.warn(
DefaultWillChangeWarning(
"`get_validate_properties_on_set` will become `True` by default "
"in the future. Set this property explicitly to `True` or `False` in "
"in the future, and may become the only option. "
"Set this property to `True` in "
f"`{cls.__module__}.{cls.__name__}._class_settings` "
"to eliminate this warning."
),
stacklevel=3,
)
return settings.get(
"validate_properties_on_set",
False,
)
return value
Loading