Sam Hooke

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 = {}