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
I'm not sure if I'm using this wrong but when I define a factory such as:
class UserFactory(factory.django.DjangoModelFactory[User]):
class Meta:
model = User
I get the following error:
Class 'FactoryMetaClass' does not define '__getitem__', so the '[]' operator cannot be used on its instances
I understand why the error occurs, but I'm not sure what the intended solution is. Since DjangoModelFactory is generic in the stubs, what's the intended usage if DjangoModelFactory isn't actually able to support getitem? Should I monkeypatch FactoryMetaClass?
The text was updated successfully, but these errors were encountered:
If you're also using typeddjango/django-stubs, a workaround is to piggy-back off of their monkey-patching:
importdjango_stubs_extimportfactory# Monkeypatching Django, so stubs will work for all generics, see: https://github.com/typeddjango/django-stubsdjango_stubs_ext.monkeypatch(
extra_classes=[
# https://github.com/youtux/types-factory-boy/issues/53factory.base.BaseFactory,
factory.declarations.BaseDeclaration,
factory.declarations.Trait,
# ...
]
)
I'm not sure if I'm using this wrong but when I define a factory such as:
I get the following error:
Class 'FactoryMetaClass' does not define '__getitem__', so the '[]' operator cannot be used on its instances
I understand why the error occurs, but I'm not sure what the intended solution is. Since DjangoModelFactory is generic in the stubs, what's the intended usage if DjangoModelFactory isn't actually able to support getitem? Should I monkeypatch FactoryMetaClass?
The text was updated successfully, but these errors were encountered: