I don't think it's a bug, but not sure:
Consider this example:
from dataclasses import dataclass
from enum import Enum
from polyfactory.factories import DataclassFactory
class BaseEnum(Enum): ...
class OtherEnum(BaseEnum): # <--- inherits from BaseEnum
VALUE_1 = 1
VALUE_2 = 2
@dataclass
class MyModel:
values: dict[BaseEnum, int] # <--- a dict with keys from the BaseEnum
class MyModelFactory(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
?
No response
Run the above example.
2.19.0
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too