Skip to content

fix: harden Photon client + consistent lifespan settings (#125, #126, #127)#131

Merged
bk86a merged 1 commit into
mainfrom
fix/photon-review-125-127
Jul 3, 2026
Merged

fix: harden Photon client + consistent lifespan settings (#125, #126, #127)#131
bk86a merged 1 commit into
mainfrom
fix/photon-review-125-127

Conversation

@bk86a

@bk86a bk86a commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Resolves the three findings from the pre-publish whole-branch review of #123, all in the new Photon geocoding code.

Changes

Tests

Closes #125
Closes #126
Closes #127

…127)

- _candidates no longer combines street+postcode when city is empty,
  matching the documented invariant; drops a wasted Photon round-trip (#125)
- _query parses coordinates inside the try/except and catches
  (TypeError, IndexError), so a non-Point feature yields None instead of
  propagating a 500 — honouring the 'never raises' contract (#126)
- lifespan reads _config.settings.* for the NUTS-polygon block, matching
  the adjacent Photon/token blocks so a monkeypatch can't desync PIP vs
  geocoder (#127)

Adds no-city and non-Point-geometry regression tests.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 867e4c285d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/photon_client.py
out.append(f"{street}, {postal_code}")
if postal_code:
out.append(postal_code)
if street and not city and not postal_code:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve street fallback when city is missing

When /resolve is called with a street but no city, postal_code is still always present, so after removing the street+postcode candidate this condition prevents any candidate containing the street from being sent. The client now queries Photon with only the postcode for these weak postal matches, which can return no_result or a coarse/wrong postcode hit despite the caller supplying street information; add a street-only candidate for this no-city case without combining it with the postcode.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked this against the module's premise before acting — I don't think it's a regression, and I'd push back on adding the street-only candidate here.

The candidate this PR removed was f"{street}, {postal_code}" — street combined with the postcode. The whole point of this module (docstring) is that Photon returns 0 results for a street+postcode string. So for a (street, no-city, postcode) input that candidate was always an empty round-trip; postcode-only was already the only query that could return a hit. Removing it changes correctness by zero and just drops the wasted request — which is what #125 asked for. No working street fallback was lost.

What you're proposing is a new street-only candidate (never combined), which is a different thing. I'd hold off on it: for a NUTS region lookup, a street with no city is low-precision — street names repeat across municipalities, so a street-alone Photon hit can land in the wrong city → wrong coordinates → wrong NUTS3. This service deliberately prefers no-result over a wrong region (0.85 geocode threshold, cross-border guard). Postcode-only is the reliable region signal for these no-city records, and "coarse" (postcode centroid) is exactly the right granularity for NUTS3.

If we do want a street-only last-resort, it should be gated and appended after the postcode query, and it's a separate enhancement rather than part of this bugfix. Happy to open an issue for it if you think the coverage is worth the precision risk.

@bk86a bk86a merged commit c97b2cc into main Jul 3, 2026
10 checks passed
@bk86a bk86a deleted the fix/photon-review-125-127 branch July 4, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant