Skip to content

fix: graceful 400 on datetime sel against a stale int64 axis#123

Open
lhoupert wants to merge 1 commit into
mainfrom
fix/issue-118-datetime-sel
Open

fix: graceful 400 on datetime sel against a stale int64 axis#123
lhoupert wants to merge 1 commit into
mainfrom
fix/issue-118-datetime-sel

Conversation

@lhoupert

Copy link
Copy Markdown
Contributor

Closes the sel half of #118 (the stale-cache fix is a separate PR).

Problem

A sel value was cast with da[dim].dtype.type(v). Against a stale/legacy int64 time axis, np.int64("2026-06-08T17:38:52") raised ValueError that escaped as HTTP 500.

Fix

Wrap the cast in try/except and raise BadRequestError (already mapped to 400). No datetime branch is added: dtype.type is already np.datetime64 for a datetime axis, so the happy path is unchanged.

Tests

  • int64 axis + ISO selBadRequestError; datetime64 happy path preserved.
  • Added a sel-tile benchmark guarding the cast path.
  • uv run pytest → 102 passed; pre-commit clean.

Split out of #119 per review.
Refs #118 (sel half; close the issue once the cache PR also lands).

🤖 Generated with Claude Code

A `sel` value was cast with `da[dim].dtype.type(v)`. Against a stale/legacy
int64 `time` axis, `np.int64("2026-06-08T17:38:52")` raised ValueError that
escaped as HTTP 500. Wrap the cast in try/except and raise BadRequestError
(already mapped to 400). No datetime branch is added: `dtype.type` is already
`np.datetime64` for a datetime axis, so the happy path is unchanged.

The sel-tile benchmark guards this cast path against regression.

Split out of #119 per review.

Refs #118 (sel half; issue closes when the cache fix lands too).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread tests/test_reader.py

def test_sel_on_int64_axis_raises_bad_request(geozarr_3d_dataset):
"""A datetime `sel` against a (stale) int64 time axis degrades to 4xx, not 500."""
from titiler.core.errors import BadRequestError

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we put this outside the function?

sel=["time=2022-01-02T00:00:00.000000000"],
)

_ = benchmark(_tile)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do we really need the benchmark this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants