Skip to content

DynamicCommunitySelection crashes with KeyError when no communities at level 0 #2382

@hanhan761

Description

@hanhan761

Description

DynamicCommunitySelection.__init__ at dynamic_community_selection.py:71 accesses self.levels["0"] directly without checking whether the key exists. If the input data contains no communities at level "0" (e.g., all communities start at level "1" or the communities list is empty), this raises KeyError: '0' and crashes the dynamic community selection flow.

Root Cause

# line 71
self.starting_communities = self.levels["0"]

self.levels is built from the communities list at lines 62-68. If no community has level="0", the key "0" is never added to the dict.

Expected Behavior

When no communities exist at level 0, starting_communities should default to an empty list ([]) so the selection gracefully yields no results instead of crashing.

Proposed Fix

Replace self.levels["0"] with self.levels.get("0", []) on line 71.

Impact

This affects users of the dynamic community selection feature (used in DRIFT search) when their indexed data has no root-level communities, which can happen with small or domain-specific datasets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions