lycantropos / hypothesis_sqlalchemy

hypothesis strategies for generating SQLAlchemy objects
MIT License
28 stars 8 forks source link

Receive None for columns with default value. #2

Closed DimitarTerzov closed 5 years ago

DimitarTerzov commented 6 years ago

In my model I have columns with default value. When the strategy generates value for this columns sometimes it generates None. Is there a way to receive the default value instead None?

I create solution that works, but I was wondering if there is another way.

videos = tables.records.factory(Video.__table__).map(
    lambda record: {column.name: _set_default_value(column, record[index]) for index, column in enumerate(Video.__table__.columns)}
)

def _set_default_value(field, field_value):
    if field.default is not None and field_value is None:
        return field.default.arg
    return field_value
lycantropos commented 6 years ago

There is no support for default values yet, but adding it won't solve original issue since some of columns seem to be nullable

DimitarTerzov commented 6 years ago

Yes, they are nullable, I tried with nullable=False and it works good, but for now I will leave them nullable and will continue this way. Thaks.