Question: uniqueness except bools
Sometimes, Faker generates duplicate values.
Faker supports a unique mode, which guarantees unique values: https://faker.readthedocs.io/en/master/#unique-values
I could implement this by changing get_fakers return value to fake.unique, but that would also apply to bools, which causes unique values (true/false) to be exhausted real quick. And I don't care about duplicate booleans.
Does Faker support excluding specific types from uniqueness (bools in this case)?
To decrease the chance of uniques, I now add unique to all Faker invocations (on instances returned by get_faker). However, this is not foolproof (one could forget to add unique), and inevitably still causes duplicates incidentally, albeit less often.
Hi @WilliamDEdwards Uniqueness in general is a very debated topic in the world of random data generation.
I agree with you that for some providers, it does not make any sense, like the boolean.
I'm exploring two approaches, the first is marking methods with annotations to skip the Uniqueness proxy, the second is to pass some configurable "exceptions" to the unique proxy.
Hi @joke2k,
I think passing exceptions to the unique proxy makes most sense.
Marking providers as being exempt from uniqueness seems like doing things in the wrong direction. In my view, providers are solely meant to provide data, not have opinions on the context they are used in.
A counter-argument to that: I think it's a safe assumption that for 99% of users, bools should not be unique, so defaulting them to be non-unique is good for DX. However:
- Making bools non-unique by default would be a breaking change
- Adding an exception to the uniqueness proxy is 2 seconds of work
Thanks for your reply!
This issue is stale because it has been open for 30 days with no activity.
Still relevant.
Hi @joke2k,
Have you made any (thinking) progress on this by any chance?