Repository navigation
fix(us): use caller-supplied pElev instead of crashing on it - #391
Merged
Merged
Conversation
rank_soils assigned pElev_dict only in the `pElev is None` branch but dereferenced it unconditionally, so a caller-supplied pElev raised UnboundLocalError (not caught by the surrounding except). Move the lookup+parse inside the `if pElev is None:` guard so a provided elevation is used as-is. Add a regression test that calls rank_soils with a numeric pElev. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
garobrik
approved these changes
Sep 25, 2026
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
rank_soilscrashed withUnboundLocalErrorwhen the caller suppliespElev(a point elevation) instead of letting the function look one up.Fix: move the lookup + parse inside the
if pElev is None:guard, so a caller-providedpElevis used as-is.Why now
The terraso-backend soil-ID elevation feature (feeding the client's elevation into the US Site score) is the first caller to actually pass
pElev. Until nowpElevwas alwaysNone, so the buggy branch was never exercised.Test
Added
test_rank_soils_accepts_caller_supplied_elevation— callsrank_soilswith a numericpElev(which skipsget_elev_data, so it's network-free and deterministic) and asserts it returns without raising. The full non-snapshot suite (157 tests) passes.🤖 Generated with Claude Code