Skip to content

Commit

Permalink
Improve exception error message (#301)
Browse files Browse the repository at this point in the history
* Improve exception message

* Update changelog

* Code linter
  • Loading branch information
berinhard committed Mar 31, 2022
1 parent 64d7709 commit f10d0a2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Extend type hints in `model_bakery.recipe` module, make `Recipe` class generic [PR #292](https://github.com/model-bakers/model_bakery/pull/292)
- Explicitly add _fill_optional parameters to baker.make and baker.prepare to aid IDE autocomplete function. [PR #264](https://github.com/model-bakers/model_bakery/pull/264)
- Fixed errors with reverse M2M relationships [PR #299](https://github.com/model-bakers/model_bakery/pull/299)
- Improve exception message for unknown field types [PR #301](https://github.com/model-bakers/model_bakery/pull/301)

### Removed

Expand Down
4 changes: 3 additions & 1 deletion model_bakery/baker.py
Expand Up @@ -672,7 +672,9 @@ def generate_value(self, field: Field, commit: bool = True) -> Any:
elif field.__class__ in self.type_mapping:
generator = self.type_mapping[field.__class__]
else:
raise TypeError("%s is not supported by baker." % field.__class__)
raise TypeError(
f"field {field.name} type {field.__class__} is not supported by baker."
)

# attributes like max_length, decimal_places are taken into account when
# generating the value.
Expand Down
1 change: 1 addition & 0 deletions tests/test_baker.py
Expand Up @@ -578,6 +578,7 @@ def test_unsupported_model_raises_an_explanatory_exception(self):
assert False, "Should have raised a TypeError"
except TypeError as e:
assert "not supported" in repr(e)
assert "field unsupported_field" in repr(e)


@pytest.mark.django_db
Expand Down

0 comments on commit f10d0a2

Please sign in to comment.