New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reproducible randomness can't be achieved on Python < 3.6 #830
Comments
Thanks for the report! This is indeed a bug, and special care had been taken to ensure that we didn't fall prey to those issues :/ The reproducible code is very useful, I'll look into it right away! Note that factory_boy's declarations use a special base class which keeps declaration in the order they were parsed by the Python interpreter. That order should also be used later on in the build steps. So, weird bug :) |
It might be of benefit to know that I opened a related issue in the Having that said, a better test code would be (to not involve the import factory, factory.random
factory.random.reseed_random(53389)
class User:
def __init__(*args, **kwargs):
print(kwargs)
class UserFactory(factory.Factory):
class Meta:
model = User
n1 = factory.Faker('name')
d1 = factory.Faker('random_digit')
u = UserFactory()
Oh, and I messed up mounting the file into a container:
Interesting idea, it didn't occur to me. But for some reason the declarations are evaluated in a random order. Unless you do this: - for field_name in declarations:
+ for field_name in declarations.sorted():
self.attributes[field_name] = getattr(self.stub, field_name) https://github.com/FactoryBoy/factory_boy/blob/3.2.0/factory/builder.py#L198 Then it all works :) Unless you're running |
FactoryBoy no longer supports Python 3.5 either. You can refer to the Support Policy to see what versions of Python are supported. |
Description
The code relies on class attributes and dicts being iterated in the declaration/insertion order.
To Reproduce
a.py
:Notes
The changing locales are partly cased by
faker
, since they are declared in adict
.In 3.6 they decided to change the
dict
implementation:In 3.7 that became official:
I decided to report the issue since I ran into it, but should it be fixed?.. I'm not sure. It can probably be closed.
The text was updated successfully, but these errors were encountered: