klen / klen/mixer

RuntimeError: Mixer (app.Model): Cannot generate a unique value for user

Open
#56 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
953
Forks
91
PR merge metrics
No merged PRs in 30d

Description

I'm getting this error in a large Django codebase with hundreds of tests. I believe this happens because all instances that mixer creates are somehow cached and after a while it runs out of dictionary words to create new instances because it compares against the cache and not against the DB (which is obviously empty after each test).

I kind of pinned it down to [this loop in main.py](https://github.com/klen/mixer/blob/develop/mixer/main.py#L256) and the fact that `TypeMixer` derives from `TypeMixerMeta` which has "Cache typemixers by scheme." as a docstring makes me think that these instances might act like singletons and are not properly destroyed between tests, so that `self.__gen_values` will probably just fill up more and more until the dictionary cannot produce unique items any more.

Is there any workaround for this?

In my case I have a `UserProfile` model which has a OneToOneKey to the `auth.User` model and I'm usually creating profiles with `mixer.blend('user_profile.UserProfile')` which then automatically also tries to mix the user for the profile.
##

---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/32818307-runtimeerror-mixer-app-model-cannot-generate-a-unique-value-for-user?utm_campaign=plugin&utm_content=tracker%2F327725&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F327725&utm_medium=issues&utm_source=github).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the failure with the Django UserProfile model and mixer.blend('user_profile.UserProfile'). Read the loop in mixer/main.py around line 256 and TypeMixerMeta's cache behavior, then compare generated values with database state between tests. Done means the reported RuntimeError no longer occurs across a large test suite, or a verified workaround is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.