Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion polyfactory/factories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __init_subclass__(cls, *args: Any, **kwargs: Any) -> None: # noqa: C901
if random_seed is not None:
cls.seed_random(random_seed)

if cls.__set_as_default_factory_for_type__:
if cls.__set_as_default_factory_for_type__ and hasattr(cls, "__model__"):
BaseFactory._factory_type_mapping[cls.__model__] = cls

@classmethod
Expand Down
20 changes: 20 additions & 0 deletions tests/test_factory_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Any, Type

from typing_extensions import TypeGuard

from polyfactory.factories.base import BaseFactory, T


def test_setting_set_as_default_factory_for_type_on_base_factory() -> None:
"""Setting the value to `True` shouldn't raise exception when initializing."""

class CustomBaseFactory(BaseFactory[T]):
__is_base_factory__ = True
__set_as_default_factory_for_type__ = True

@classmethod
def is_supported_type(cls, value: Any) -> TypeGuard[Type[T]]:
# Set this as false since this factory will be injected into the
# list of base factories, but this obviously shouldn't be ran
# for any of the types.
return False