Repository: litestar-org/polyfactory (python)

Issue:
Bug: settings `__set_as_default_factory_for_type__ ` to `True` on base factory fails
### Description

If `__set_as_default_factory_for_type__ ` is set to `True` on a custom base factory so that all the subclasses factories inherit that value, then an `AttributeError` is raised.

### URL to code causing the issue

_No response_

### MCVE

```python
from polyfactory.factories import DataclassFactory
from polyfactory.factories.base import T


class CustomDataclassBaseFactory(DataclassFactory[T]):
    __is_base_factory__ = True
    __set_as_default_factory_for_type__ = True
```


### Steps to reproduce

```bash
Run the MCVE.
```


### Screenshots

_No response_

### Logs

_No response_

### Release Version

2.13.0

### Platform

- [ ] Linux
- [ ] Mac
- [ ] Windows
- [ ] Other (Please specify in the description above)

<!-- POLAR PLEDGE BADGE START -->
---
> [!NOTE]  
> While we are open for sponsoring on [GitHub Sponsors](https://github.com/sponsors/litestar-org/) and 
> [OpenCollective](https://opencollective.com/litestar), we also utilize [Polar.sh](https://polar.sh/) to engage in pledge-based sponsorship.
>
> Check out all issues funded or available for funding [on our Polar.sh dashboard](https://polar.sh/litestar-org)
> * If you would like to see an issue prioritized, make a pledge towards it!
> * We receive the pledge once the issue is completed & verified
> * This, along with engagement in the community, helps us know which features are a priority to our users.

<a href="https://polar.sh/litestar-org/polyfactory/issues/476">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/polyfactory/issues/476/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/polyfactory/issues/476/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->


Pull request description:
fix: set as default type for factory only if model is defined
<!--
By submitting this pull request, you agree to:
- follow [Litestar's Code of Conduct](https://github.com/litestar-org/.github/blob/main/CODE_OF_CONDUCT.md)
- follow [Litestar's contribution guidelines](https://github.com/litestar-org/.github/blob/main/CONTRIBUTING.md)
- follow the [PSFs's Code of Conduct](https://www.python.org/psf/conduct/)
-->

### Description
<!--
Please describe your pull request for new release changelog purposes
-->

When `__set_as_default_factory_for_type__` is set tot `True`, we try to access the `__model__` in order to map the type to the factory. However, in base factories, the '__model__' will not be defined and so it an 'AttributeError' will be raised when trying to access 'cls.__model__'. So, we simply ensure that '__model__' defined before trying to access it.


### Close Issue(s)
<!--
Please add in issue numbers this pull request will close, if applicable
Examples: Fixes #4321 or Closes #1234
-->

- Fixes #476.


Patch:
diff --git a/polyfactory/factories/base.py b/polyfactory/factories/base.py
index 3893b7b..71b0407 100644
--- a/polyfactory/factories/base.py
+++ b/polyfactory/factories/base.py
@@ -223,7 +223,7 @@ class BaseFactory(ABC, Generic[T]):
         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


Test patch:
diff --git a/tests/test_factory_configuration.py b/tests/test_factory_configuration.py
new file mode 100644
index 0000000..aa92869
--- /dev/null
+++ b/tests/test_factory_configuration.py
@@ -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