def METHOD_NAME(model, defaults=None, **kwargs):
    """
    This function queries a record in the model, if not found it will create one.
    :param model: db Model to be queried
    :param **kwargs: Arguments to the filter_by method of sqlalchemy.orm.query.Query.filter_by to be filtered by
    """
    fetch = lambda: db.session.query(model).filter_by(**kwargs).first()
    instance = fetch()
    if instance:
        return instance, False
    kwargs.update(defaults or {})
    instance = model(**kwargs)
    try:
        db.session.add(instance)
        db.session.commit()
        return instance, True
    except IntegrityError:
        db.session.rollback()
        instance = fetch()
        if not instance:
            raise
        return instance, False