def root_serializer(self):
        """Return the root serializer (serializer for the primary resource)."""
        if not self.parent:
            # Don't cache, so that we'd recompute if parent is set.
            return None

        node = self
        seen = set()
        while True:
            seen.add(node)
            if getattr(node, 'parent', None):
                node = node.parent
                if node in seen:
                    return None
            else:
                return node
def root_serializer ( self ) : if not self . parent : return None node = self seen = set ( ) while True : seen . add ( node ) if getattr ( node , 'parent' , None ) : node = node . parent if node in seen : return None else : return node
Return the root serializer (serializer for the primary resource).