Skip to content

run GraphCommands.explain raise TypeError #1848

Closed
@ChandlerBent

Description

@ChandlerBent

Version: 4.1.0

Python Version: 3.8

Platform: MacOS 12.0.1

Description: I'm using redisgraph:2.8.7 with redis-py. I met a error when I run explain. Error:

graph.explain('match (n:person) where n.name = "ken" return n')

raise exception

File "/lib/python3.8/site-packages/redis/commands/graph/commands.py", line 140, in explain
    return "\n".join(plan)
TypeError: sequence item 0: expected str instance, bytes found
graph.execute_command('GRAPH.EXPLAIN', graph.name, 'match (n:person) where n.name = "ken" return n')

return

[b'Results',
 b'    Project',
 b'        Filter',
 b'            Node By Label Scan | (n:person)']

The problem is the result that type is List[byte].
I guess the code should modify as this:

    def explain(self, query, params=None):
        """
        Get the execution plan for given query,
        Returns an array of operations.
        For more information see `GRAPH.EXPLAIN <https://oss.redis.com/redisgraph/master/commands/#graphexplain>`_. # noqa

        Args:

        -------
        query:
            The query that will be executed.
        params: dict
            Query parameters.
        """
        if params is not None:
            query = self._build_params_header(params) + query

        plan = self.execute_command("GRAPH.EXPLAIN", self.name, query)
        return "\n".join([b.decode() for b in plan])

or

    def explain(self, query, params=None):
        """
        Get the execution plan for given query,
        Returns an array of operations.
        For more information see `GRAPH.EXPLAIN <https://oss.redis.com/redisgraph/master/commands/#graphexplain>`_. # noqa

        Args:

        -------
        query:
            The query that will be executed.
        params: dict
            Query parameters.
        """
        if params is not None:
            query = self._build_params_header(params) + query

        plan = self.execute_command("GRAPH.EXPLAIN", self.name, query)
        return plan

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions