fix: TypeError traversing conversation tree with timestamp-less utterances - #352
Open
devteamaegis wants to merge 1 commit into
Open
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's broken
UtteranceNode.set_childrensorts sibling nodes byutt.timestamp, butUtterance.timestampisOptional[int]and defaults toNone(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):Why it happens
sorted(..., key=lambda w: w.utt.timestamp)compares key values, andNone < Noneis unorderable. The code assumedtimestampis always set; the chronological-list helpers already guard this, butset_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 comparingNone.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.