Skip to content

Bug: encode_node mutates its argument #570

@gkorland

Description

@gkorland

Description

In api/entities/entity_encoder.py:7, encode_node removes the 'Searchable' label from the node object:

def encode_node(n: Node) -> dict:
    n.labels.remove('Searchable')
    return vars(n)

This modifies the original node in place. Encoding the same node twice will raise ValueError because 'Searchable' is already removed on the second call.

Impact

  • Encoding a node is destructive — the original node object loses the label
  • Encoding the same node twice crashes with ValueError: list.remove(x): x not in list

Suggested Fix

Create a copy of the labels instead of modifying in place:

def encode_node(n: Node) -> dict:
    result = vars(n).copy()
    result['labels'] = [l for l in n.labels if l != 'Searchable']
    return result

Context

Found during code review of PR #522.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions