klen / mixer

Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.
Other
939 stars 96 forks source link

Unable to generate unique uuids #135

Closed rvinzent closed 3 years ago

rvinzent commented 3 years ago

No matter what method I try, I cannot seem to generate unique UUIDs. This seems like something that would be super basic so I'm really struggling to find the right method here.

import uuid
from django.db import models
from mixer.backend.django import mixer

class MyModel(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4)

objs = mixer.cycle(2).blend(MyModel)  # raises unique constraint violation, please just use my default callable
objs = mixer.cycle(2).blend(MyModel, id=uuid.uuid4)  # ok I would have at least expected this to work

mixer.register(MyModel, id=uuid.uuid)  # nope!
objs = mixer.cycle(2).blend(MyModel)

objs =[mixer.blend(MyModel, id=uuid.uuid4) for _ in range(2)]  # nope!

Am I missing something? I wish it would just use the callable default value defined on the model, or at least any of the other methods. The thing about UUIDs is that you don't have to fake them, just call the real function every time.

rvinzent commented 3 years ago

closing, it was related to a base class silently causing mixer to not work properly somehow