-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Adjust min/max items to valid lengths for Set[Enum] fields #567
Conversation
The question from #565 about whether this should raise an error instead or warn in addition remains open. |
For `Set[Enum]` fields with a limited maximum length, adjust `min_items` and `max_items` to be within the range of valid lengths.
3cac77f
to
7cd5a7e
Compare
I am not really sure whether this is sufficient for handling all possible ways of defining fields with enums? Or whether |
What if we just don't handle this? Instead, we could just raise an exception telling the user the minimum is too large. It might be due to the default set by polyfactory, but this way we can tell the user to change it themselves. I don't really like the idea of us just changing a value without them knowing. I don't think it would be a breaking change either since it currently results in an infinite loop anyway. |
Thanks for the review! I think I addressed all the individual suggestions, although handling In terms of raising an error or not, I'm not particularly familiar with polyfactory so it might just be my understanding, but it seems difficult to configure the min/max length on a per-item basis. How would you (easily) set the intended lengths for a model like this? class WithSetEnum(BaseModel):
letters: Set[Enum("Letters", ["a", "b", "c", "d", "e", "f"])]
colors: Set[Enum("Colors", ["red", "green"])] |
Yeah this is a bit tricky since you'd have to set the min val as 0 and max val as 2. I'm not sure what the best way to go about this would be. You could also have a classmethod for generating the values for that specific field and manually call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @adrianeboyd, sorry for the super late reply! I think if we can fix those things regarding the Literal
, then this is good to go :)
- `min_items` should be at most the number of possible values - `max_items` for `Literal` should be the number of possible values - `max_items` for both `Enum` and `Literal` shouldn't clobber a provided `max_items` that's lower than the number of possible values - run the sanity check for `min_items <= max_items` before any values are modified
Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/567 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adrianeboyd so sorry for keeping you waiting! Life got in the way and I've been super busy. All the changes look good to me :) Thanks so much!
Description
For
Set[Enum]
fields with a limited maximum length, adjustmin_items
andmax_items
to be within the range of valid lengths.Closes
Fixes #565