Closed alessio-locatelli closed 11 months ago
@olk-m thanks for reporting this. The Annotated.__metadata__
is already being parsed in order to generate values that satisfy the constraints. So, it seems there's some bug where it's not getting parsed or something. Also, the error message is indeed unexpected.
The reason this was failing is because polyfactory
will sometimes create an empty string which fails the validation call to str.isupper
. The exception thrown here was being supressed by polyfactory
instead of properly allowing it to be raised. This has been fixed in #450.
This now poses a question on how to handle the cases where isupper
or islower
constraints are provided, but no min_length
constraint is given. The options are:
min_length
is not providedmin_length
is not providedPersonally, I'm leaning towards the first option. It's more explicit whereas the second option is implicit.
Thank you for a quick response.
Personally, I'm leaning towards the first option.
I agree that if a user uses a bare str
or Annotated[str, IsUpper]
(without MinLen(1)
) then polyfactory should not silently default to a non-empty string.
Description
Problem 1
Can not handle
Predicate
in a model that is used in a field of a primary model.Problem 2
Misleading, wrong error.
The error says
polyfactory.exceptions.ParameterException: received constraints for unsupported type list[__main__.Pet]
but the real error is much deeper, in a specific field:MCVE
Logs
Expected behavior
Ignore
Annotated.__metadata__
in a model that is used in a field and continue execution.Release Version
Version: 2.12.0
Platform