Sam Hooke

These are rough notes from whatever I was working on, interested in or thinking about at the time. They vary greatly in quality and length, but prove useful to me, and hopefully to you too!

Tastypie "TypeError of type 'NoneType' is not iterable"

A unit test which performed a GET to a Tastypie endpoint always raised the error:

    def check_filtering(self, field_name, filter_type='exact', filter_bits=None):
        """
            Given a field name, a optional filter type and an optional list of
            additional relations, determine if a field can be filtered on.

            If a filter does not meet the needed conditions, it should raise an
            ``InvalidFilterError``.

            If the filter meets the conditions, a list of attribute names (not
            field names) will be returned.
            """
        if filter_bits is None:
            filter_bits = []

>       if field_name not in self._meta.filtering:
E       TypeError: argument of type 'NoneType' is not iterable

The fix was to define filtering to at least be an empty dictionary in the Tastypie resource. For example:

class FooResource(Resource):
    class Meta:
        filtering = {}
<< Previous: Using a non-pk as a foreign key in a Tastypie endpoint
Next: Captured `SystemExit` with pytest and tox >>