Skip to content

Commit

Permalink
Change: Improve error message when a model value can't be set
Browse files Browse the repository at this point in the history
Make the error message more precise in what's wrong here actually.
  • Loading branch information
bjoernricks committed Sep 27, 2023
1 parent a31ae3c commit c3d18b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pontos/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def from_dict(cls, data: Dict[str, Any]):
value = cls._get_value(model_field_cls, value) # type: ignore # pylint: disable=line-too-long # noqa: E501
except TypeError as e:
raise ModelError(
f"Error while creating {cls.__name__}. Could not set value "
f"for '{name}' from '{value}'."
f"Error while creating {cls.__name__} model. Could not set "
f"value for property '{name}' from '{value}'."
) from e

if name in type_hints:
Expand Down
4 changes: 2 additions & 2 deletions tests/models/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class ExampleModel(Model):

with self.assertRaisesRegex(
ModelError,
"Error while creating ExampleModel. Could not set value for 'foo' "
"from '{'bar': 'baz'}'.",
"Error while creating ExampleModel model. Could not set value for "
"property 'foo' from '{'bar': 'baz'}'.",
):
ExampleModel.from_dict({"foo": {"bar": "baz"}})

0 comments on commit c3d18b8

Please sign in to comment.