Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

KeyError in graph_tool #121

@jtseven

Description

@jtseven

Within the get_node_type method in graph_tool.py there is an if-clause to check, if a certain key exists in graph.keys(), but if it fails, accessing the key is still tried and will fail with a KeyError:

def get_node_type(self, name):
    if name in self.graph.keys() and "attr" in self.graph[name].keys():  # <-- Check if name is in keys
        return self.graph[name]["attr"]["type"]
    else:
        logging.info(name, self.graph[name])  # <-- Causes key error
    return None

Instead, something like that could be done:

logging.info(name, self.graph.get(name, "Name not in graph"))

I'm not sure if it is expected behavior that the name does not exist within the keys. If it's not, a different, more precise error message should be printed and an exception should be raised accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions