importing "Litestar" somehow makes "Faker" Not Random anymore #1945
Replies: 5 comments
-
Litestar uses polyfactory to generate openapi examples. It seeds the random seed for random to ensure that the examples are deterministic. You can set a different random seed on faker after importing litestar to override this. Why does this happen? The reason is that faker no longer supports seeding a per faker random seed but rather requiires a global random seed. |
Beta Was this translation helpful? Give feedback.
-
Already closed the issue! I did some tests with other libraries and found that they work well with Faker. Here's an example code snippet using different libraries: import faker
import starlette
import fastapi
import flask
import sanic
import quart
fake = faker.Faker()
print(fake.md5()) The outputs :
It seems that other libraries and Faker handle the seeds correctly. However, Litestar is somehow "messing" with the seeds. The Faker maintainer responded with the following comment:
Quick question: I attempted to disable the |
Beta Was this translation helpful? Give feedback.
-
Well this is a pretty useless exercise. I already explained what you're seeing. The issue is closed because this is not a bug. I can convert it to a discussion instead.
Not at present. We could consider adding this but it's a very marginal use case, since you can simply set a seed on your own and even abstract this stuff into a fixture. I need to understand why exactly this is a big issue for you? As to the other question - if faker supports seed random per faker instance it will prevent this issue. The problem is the use of a global namespace. |
Beta Was this translation helpful? Give feedback.
-
Issue should be resolved @saltcable - if you install latest polyfactory (2.6.2) this should fix it for you. |
Beta Was this translation helpful? Give feedback.
-
Faker is working fine but when Litestar is imported, it's not random anymore. Same result/output every time.
Steps to reproduce
Expected behavior (by removing
import litestar
)Random output all the time
7442b46046a7c2d7ca080483a0d45ad4
a87b76986a9afbb9da63dde9ed4d2495
6924bc922dd1db07440ec3298c42afb8
Actual behavior (same environment)
Same every time. for all the functions
9fc4f6348d3311fa3376be5aa395877a
9fc4f6348d3311fa3376be5aa395877a
9fc4f6348d3311fa3376be5aa395877a
Funding
Beta Was this translation helpful? Give feedback.
All reactions