Bug: 2.7.1 break faker locale generator
SteinRobert opened this issue · 4 comments
SteinRobert commented
Description
After upgrading from 2.7.0 to 2.7.1 my tests fail due to a change in how faker is used.
Error:
/factories.py:93: in vat_identifier
return cls.__faker__.vat_id()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <faker.proxy.Faker object at 0x103626ad0>, attr = 'vat_id'
def __getattr__(self, attr: str) -> Any:
"""
Handles cache access and proxying behavior
:param attr: attribute name
:return: the appropriate attribute
"""
if len(self._factories) == 1:
> return getattr(self._factories[0], attr)
E AttributeError: 'Generator' object has no attribute 'vat_id'
URL to code causing the issue
No response
MCVE
# Works in 2.7.0 not in 2.7.1:
class SellerFactory(ModelFactory[Seller]):
__model__ = Seller
__set_as_default_factory_for_type__ = True
__faker__ = Faker(locale="de_DE")
__random_seed__ = 10
@classmethod
def vat_identifier(cls) -> str:
return cls.__faker__.vat_id()
Steps to reproduce
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
Screenshots
"In the format of: ![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)
"
Logs
No response
Release Version
2.7.1
Platform
- Linux
- Mac
- Windows
- Other (Please specify in the description above)
Funding
- If you would like to see an issue prioritized, make a pledge towards it!
- We receive the pledge once the issue is completed & verified
SteinRobert commented
Thank you very much! Do you know when's the next release?
guacs commented
@SteinRobert sorry for the delay, but I'm not sure exactly when the next release is going to be. It might take a bit of time actually.
For the time being, you could do two things:
-
pin
polyfactory
to a version that does not break things -
override the
seed_random
method on the factory that you're usingFaker
with the following piece of code:@classmethod def seed_random(cls, seed) -> None: cls.__random__ = Random(seed) cls.__faker__.seed_instance(seed)