You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromdataclassesimportdataclassfromenumimportEnumfrompolyfactory.factoriesimportDataclassFactoryclassBaseEnum(Enum): ...
classOtherEnum(BaseEnum): # <--- inherits from BaseEnumVALUE_1=1VALUE_2=2@dataclassclassMyModel:
values: dict[BaseEnum, int] # <--- a dict with keys from the BaseEnumclassMyModelFactory(DataclassFactory[MyModel]): ...
if__name__=="__main__":
my_model=MyModelFactory.build()
This will raise an IndexError: IndexError: Cannot choose from an empty sequence.
Which is obvious as Litestar will try to populate the keys in the values dict by doing this: __random__(list(BaseEnum)). That results in an empty list which gives the error.
But the BaseEnum (which I don't have control over) is only the base enum for the OtherEnum which does contain values.
Is there any way in my factory to tell when BaseEnum is encountered it should pick values from OtherEnum ?
URL to code causing the issue
No response
MCVE
Steps to reproduce
Run the above example.
Screenshots
Logs
Release Version
2.19.0
Platform
Linux
Mac
Windows
Other (Please specify in the description above)
The text was updated successfully, but these errors were encountered:
I think you mean I explicity/manually fill the values dictionary?.
I could do that, but my problem is that my real data is really nested and that would require me to do the manual filling in a lot of places.
I have indeed no control of the shape of my model. So
Description
I don't think it's a bug, but not sure:
Consider this example:
This will raise an IndexError:
IndexError: Cannot choose from an empty sequence
.Which is obvious as Litestar will try to populate the keys in the
values
dict by doing this:__random__(list(BaseEnum))
. That results in an empty list which gives the error.But the BaseEnum (which I don't have control over) is only the base enum for the
OtherEnum
which does contain values.Is there any way in my factory to tell when
BaseEnum
is encountered it should pick values fromOtherEnum
?URL to code causing the issue
No response
MCVE
Steps to reproduce
Screenshots
Logs
Release Version
2.19.0
Platform
The text was updated successfully, but these errors were encountered: