klen / mixer

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

Data generation and UUIDType from SQLAlchemy Utils #73

Closed frankrousseau closed 7 years ago

frankrousseau commented 7 years ago

Hello there,

Thank you for mixer, it is a very useful tool. I use it to test an API based on Flask Restful and Postgres. But I face an issue. When I want to use a UUIDType column in my database schema, it is not recognized and Mixer can't give a value to it (this type comes from SQLAlchemy utils).

I tried this solution:

from mixer.backend.sqlalchemy import GenFactory
GenFactory.generators[UUIDType] = my_generator

But it doesn't work. Do you have any idea about what to do to make it work?

frankrousseau commented 7 years ago

I solved my problem by forcing the generator each time I generate objects:

import uuid
mixer.blend(Car, id=uuid.uuid4)
ei-grad commented 6 years ago

I came to the following solution to use PostgreSQL UUIDs:

from sqlalchemy.dialects import postgresql as pg
from mixer.backend.sqlalchemy import Mixer, GenFactory
from mixer import mix_types

class MyFactory(GenFactory):
    types = dict(GenFactory.types)
    types[pg.UUID] = mix_types.UUID

mixer = Mixer(factory=MyFactory)