Skip to content

[BUG] : State Mutation Bug in Graph Build Phase #796

Description

@suhaniiz

Description of the Bug

The build_graph function calls _convert_sets_for_json(graph) immediately before returning the graph object. Because Python objects are passed by reference, this permanently mutates the graph's internal node and edge attributes (pages and chunks) from mutable Python set objects into sorted list objects. If this graph object is kept in memory to process additional chunks later, subsequent calls will attempt to invoke .add() on a list, resulting in an unhandled AttributeError crash.

Steps to Reproduce

Initialize or pass a list of chunks to build_graph(chunks).

Keep the returned graph object in memory.

Attempt to process a new batch of text chunks using the same graph object via a loop or sequential function calls.

Observe the unhandled exception when an entity is encountered a second time.

Expected Behavior

The core nx.Graph object should maintain its data types (set) consistently throughout its in-memory lifecycle so it can be appended to or modified safely. Data type conversion for serialization constraints should only happen on a transient copy of the graph or natively during the serialization routine inside save_graph.

Screenshots / Logs

No response

Environment

GSSoC '26

  • Yes, I am participating in GirlScript Summer of Code and would like to fix this.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggssocGirlScript Summer of Code 2026 issue/PR

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions