Fix UnboundLocalError when OSM header has non-numeric sequence number - #315
Open
xovishnukosuri wants to merge 1 commit into
Open
xovishnukosuri wants to merge 1 commit into
xovishnukosuri wants to merge 1 commit into
Conversation
…numeric In get_replication_header(), the warning log for an invalid sequence number referenced `seq` instead of `seqstr`. Because `seq` is only assigned inside the try block and the assignment fails when the string is non-numeric, `seq` is unbound at the point of the except handler, causing an UnboundLocalError that completely silences the intended warning and crashes the function. Replace `seq` with `seqstr` in the warning call so the raw string value that failed parsing is reported. Add two tests that cover the invalid-sequence and negative-sequence paths, both of which were previously untested. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
get_replication_header()insrc/osmium/replication/utils.pycrashes withUnboundLocalErrorwhen an OSM file header contains a non-numericosmosis_replication_sequence_numbervalue.except ValueErrorhandler loggedseqinstead ofseqstr. Sinceseqis only assigned inside thetryblock and the assignment fails for non-numeric strings,seqis unbound at the point the warning is emitted.seqwithseqstrso the raw invalid string is reported, matching the intent of the warning message.Root cause
Test plan
test_get_replication_header_invalid_sequence— verifies the function returnssequence=Noneand logs the bad string without raisingtest_get_replication_header_negative_sequence— verifies the existing negative-value path also works and logs correctly🤖 Generated with Claude Code