# Buggy code
def text(alphabet=None, min_size=None, average_size=None, max_size=None):
    """Generates values of a unicode text type (unicode on python 2, str on
    python 3) with values drawn from alphabet, which should be an iterable of
    length one strings or a strategy generating such. If it is None it will
    default to generating the full unicode range. If it is an empty collection
    this will only generate empty strings.

    min_size, max_size and average_size have the usual interpretations.

    Examples from this strategy shrink towards shorter strings, and with the
    characters in the text shrinking as per the alphabet strategy.

    """
    from hypothesis.searchstrategy.strings import StringStrategy

    if alphabet is None:
        char_strategy = characters(blacklist_categories=("Cs",))
    elif not alphabet:
        if (min_size or 0) > 0:
            raise InvalidArgument(
                "Invalid min_size %r > 0 for empty alphabet" % (min_size,)
            )
        return just("")
    elif isinstance(alphabet, SearchStrategy):
        char_strategy = alphabet
    else:
        char_strategy = sampled_from(list(map(text_type, alphabet)))
    return StringStrategy(
        lists(
            char_strategy,
            average_size=average_size,
            min_size=min_size,
            max_size=max_size,
        )
    )


# Traceback (ValueError)
Error
Traceback (most recent call last):
File "/vagrant/savings_champion/products/tests/models.py", line 33, in test_check_bonus
user=models(User),
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/core.py", line 1001, in wrapped_test
state.run()
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/core.py", line 725, in run
runner.run()
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/engine.py", line 393, in run
self._run()
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/engine.py", line 791, in _run
self.generate_new_examples()
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/engine.py", line 706, in generate_new_examples
self.test_function(last_data)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/engine.py", line 153, in test_function
self._test_function(data)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/core.py", line 691, in evaluate_test_data
escalate_hypothesis_internal_error()
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/core.py", line 663, in evaluate_test_data
result = self.execute(data, collect=True)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/core.py", line 578, in execute
result = self.test_runner(data, run)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/executors.py", line 78, in <lambda>
lambda: function(data)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/executors.py", line 33, in execute
return function()
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/executors.py", line 78, in <lambda>
lambda: function(data)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/core.py", line 552, in run
args, kwargs = data.draw(self.search_strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 121, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 136, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/core.py", line 180, in do_draw
return self.base.do_draw(data)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/lazy.py", line 158, in do_draw
return data.draw(self.wrapped_strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 60, in do_draw
data.draw(e) for e in self.element_strategies
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 56, in newtuple
return tuple(xs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 60, in <genexpr>
data.draw(e) for e in self.element_strategies
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/strategies.py", line 507, in do_draw
return self.pack(data.draw(self.mapped_strategy))
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/lazy.py", line 158, in do_draw
return data.draw(self.wrapped_strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/strategies.py", line 507, in do_draw
return self.pack(data.draw(self.mapped_strategy))
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 60, in do_draw
data.draw(e) for e in self.element_strategies
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 56, in newtuple
return tuple(xs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 60, in <genexpr>
data.draw(e) for e in self.element_strategies
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/lazy.py", line 158, in do_draw
return data.draw(self.wrapped_strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/strategies.py", line 1550, in do_draw
return f(draw, *args, **kwargs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/extra/django/models.py", line 161, in _models_impl
return draw(strat)[0]
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/strategies.py", line 1548, in draw
return data.draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/strategies.py", line 507, in do_draw
return self.pack(data.draw(self.mapped_strategy))
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/lazy.py", line 158, in do_draw
return data.draw(self.wrapped_strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 60, in do_draw
data.draw(e) for e in self.element_strategies
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 56, in newtuple
return tuple(xs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 60, in <genexpr>
data.draw(e) for e in self.element_strategies
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/strategies.py", line 507, in do_draw
return self.pack(data.draw(self.mapped_strategy))
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 60, in do_draw
data.draw(e) for e in self.element_strategies
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 56, in newtuple
return tuple(xs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/collections.py", line 60, in <genexpr>
data.draw(e) for e in self.element_strategies
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/strategies.py", line 1550, in do_draw
return f(draw, *args, **kwargs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/extra/django/models.py", line 161, in _models_impl
return draw(strat)[0]
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/strategies.py", line 1548, in draw
return data.draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 125, in draw
return self.__draw(strategy)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/internal/conjecture/data.py", line 132, in __draw
return strategy.do_draw(self)
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/searchstrategy/strategies.py", line 507, in do_draw
return self.pack(data.draw(self.mapped_strategy))
File "/home/ubuntu/.local/lib/python3.5/site-packages/hypothesis/strategies.py", line 970, in <lambda>
lambda value: target(*value[0], **value[1])
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/models/query.py", line 487, in get_or_create
return self.get(**lookup), False
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/models/query.py", line 397, in get
num = len(clone)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/models/query.py", line 254, in __len__
self._fetch_all()
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/models/query.py", line 1179, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1063, in execute_sql
cursor.execute(sql, params)
File "/home/ubuntu/.local/lib/python3.5/site-packages/raven/contrib/django/client.py", line 123, in execute
return real_execute(self, sql, params)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
ValueError: A string literal cannot contain NUL (0x00) characters.

# Fixed code
def text(alphabet=None, min_size=None, average_size=None, max_size=None):
    """Generates values of a unicode text type (unicode on python 2, str on
    python 3) with values drawn from alphabet, which should be an iterable of
    length one strings or a strategy generating such. If it is None it will
    default to generating the full unicode range (excluding surrogate
    characters). If it is an empty collection this will only generate empty
    strings.

    min_size, max_size and average_size have the usual interpretations.

    Examples from this strategy shrink towards shorter strings, and with the
    characters in the text shrinking as per the alphabet strategy.

    """
    from hypothesis.searchstrategy.strings import StringStrategy

    if alphabet is None:
        char_strategy = characters(blacklist_categories=("Cs",))
    elif not alphabet:
        if (min_size or 0) > 0:
            raise InvalidArgument(
                "Invalid min_size %r > 0 for empty alphabet" % (min_size,)
            )
        return just("")
    elif isinstance(alphabet, SearchStrategy):
        char_strategy = alphabet
    else:
        char_strategy = sampled_from(list(map(text_type, alphabet)))
    return StringStrategy(
        lists(
            char_strategy,
            average_size=average_size,
            min_size=min_size,
            max_size=max_size,
        )
    )