litestar-org / polyfactory

Simple and powerful factories for mock data generation
https://polyfactory.litestar.dev/
MIT License
1k stars 78 forks source link

fix: set as default type for factory only if model is defined #479

Closed guacs closed 8 months ago

guacs commented 8 months ago

Description

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)

sonarcloud[bot] commented 8 months ago

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

github-actions[bot] commented 8 months ago

Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/479