Skip to content

fix: TypeError traversing conversation tree with timestamp-less utterances - #352

Open
devteamaegis wants to merge 1 commit into
CornellNLP:masterfrom
devteamaegis:fix/utterancenode-none-timestamp-sort
Open

fix: TypeError traversing conversation tree with timestamp-less utterances#352
devteamaegis wants to merge 1 commit into
CornellNLP:masterfrom
devteamaegis:fix/utterancenode-none-timestamp-sort

Conversation

@devteamaegis

Copy link
Copy Markdown

What's broken

UtteranceNode.set_children sorts sibling nodes by utt.timestamp, but Utterance.timestamp is Optional[int] and defaults to None (many corpora have no timestamps). A conversation with two or more sibling utterances that both reply to the same parent and both lack timestamps crashes every tree operation (traverse, get_subtree, get_longest_paths, get_root_to_leaf_paths):

TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'  (utteranceNode.py:19)

Why it happens

sorted(..., key=lambda w: w.utt.timestamp) compares key values, and None < None is unorderable. The code assumed timestamp is always set; the chronological-list helpers already guard this, but set_children (inside tree construction) didn't.

Fix

Sort with key (timestamp is None, timestamp or 0): timestamped utterances ascending, None-timestamp ones last in stable insertion order, never comparing None.

Test

Added test_traverse_no_timestamps (root + two timestamp-less children) to the existing traverse suite. Fails before, passes after; existing timestamped-ordering tests unchanged.

…ck timestamps

UtteranceNode.set_children sorted sibling nodes by utt.timestamp. Since
timestamp is optional and defaults to None, any conversation with two or
more sibling utterances missing timestamps crashed every tree operation
(traverse, get_subtree, get_longest_paths, get_root_to_leaf_paths via
initialize_tree_structure) with:
    TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'

Sort with key (timestamp is None, timestamp or 0) so missing-timestamp
utterances sort last (in stable insertion order) and None is never
compared. Existing timestamped ordering is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant