[Fixed]-Python / Django Rest Framework weird error happening only when using debugger

4👍

SOLUTION: First of all it seems to me that there is a bug with either pydevd or Django Rest Framework, that made my code work when in debugging mode and stoping in breakpoints (showed in the video). But I am not expert in Django / Python so it could be the expected behaviour.

As seen in the code above, the ChHiveLevel1Serializer serializer has nested serializers, being one of them, for example, ChPublicChatLevel1Serializer. Lets see how this serializer looks like:

class ChCommunityPublicChatListLevel1Serializer(serializers.ModelSerializer):
"""Used by the following API methods: GET hive list,

"""
    chat = serializers.SlugRelatedField(read_only=True, slug_field='chat_id', allow_null=True)

    class Meta:
        model = ChCommunityPublicChat
        fields = ('chat')

As the error said, fields is defined as a string instead of a tuple. The correct form would be:

class ChCommunityPublicChatListLevel1Serializer(serializers.ModelSerializer):
"""Used by the following API methods: GET hive list,

"""
    chat = serializers.SlugRelatedField(read_only=True, slug_field='chat_id', allow_null=True)

    class Meta:
        model = ChCommunityPublicChat
        fields = ('chat', )

While I agree that I made a mistake in how i defined this tuple, I still can’t understand why with the debugger set to ON, it would just work. (like if using the debugger and stopping in breakpoints it suddenly interprets (‘chat’) as a tuple instead of a string).

Leave a comment