Normalize geo codes consistently (Copilot review on #26) - #31
Merged
Conversation
Copilot flagged that geo handling normalized inconsistently:
* line_item_locale uppercased but didn't strip, so a brief geo like "PT "
failed the pycountry lookup and silently fell back to US, even though the
targeting resolver (which strips) resolved it fine;
* _resolve_geos recorded unresolved entries using the raw padded/lowercased
input rather than the normalized code.
Normalize each geo code once with strip().upper() and use that form for the
lookup, the locale, and the unresolved report. Adds tests for whitespace/case
tolerance in both resolution and locale, and that unresolved codes surface
normalized.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
th0rz05
added a commit
that referenced
this pull request
Jun 9, 2026
Copilot flagged that geo handling normalized inconsistently:
* line_item_locale uppercased but didn't strip, so a brief geo like "PT "
failed the pycountry lookup and silently fell back to US, even though the
targeting resolver (which strips) resolved it fine;
* _resolve_geos recorded unresolved entries using the raw padded/lowercased
input rather than the normalized code.
Normalize each geo code once with strip().upper() and use that form for the
lookup, the locale, and the unresolved report. Adds tests for whitespace/case
tolerance in both resolution and locale, and that unresolved codes surface
normalized.
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
Addresses both inline comments from Copilot's review of #26 — geo codes were normalized inconsistently across the two places that consume them:
line_item_locale(mapping.py) uppercased but did not strip whitespace. A brief geo like"PT "failed thepycountrylookup and silently fell back to US — even though the targeting resolver (which strips inside_country_name) resolved the same value correctly. So targeting and locale could disagree._resolve_geos(targeting.py) recordedunresolvedentries using the raw input string (e.g."pt ") rather than the normalized code.Fix
Normalize each geo code once with
strip().upper()and use that single form for the typeahead lookup, the locale country, and the unresolved report.Tests
us/Pt(padded + mixed case) still resolve to the US/PT URNs."zz ") surfaces as the normalized"ZZ"inunresolved.line_item_locale(["pt "])→{"country": "PT", ...}(no longer falls back to US); unknown code still defaults to US.47 tests pass; ruff clean.