Skip to content

Refuse a negative limit or offset - #1576

Merged
frenck merged 1 commit into
mainfrom
frenck/validate-paging
Oct 1, 2026
Merged

frenck merged 1 commit into
mainfrom
frenck/validate-paging

Conversation

@frenck

@frenck frenck commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Breaking change

A negative limit or offset now raises a ValueError before a request is sent. It used to be passed on as is.

Proposed change

Found in a second review of the library. Since countries() pages locally (#1568, #1574), a negative limit or offset went straight into Python slicing: countries(limit=-1) silently returned every country except the last one. For the other list methods, the value was passed on to the API.

A small validate_paging() now refuses a negative limit or offset in all five list methods (countries(), languages(), tags(), stations() and search()), next to the existing order validation.

Type of change

  • Dependency or tooling upgrade
  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Deprecation (replaces or removes a feature, with a migration path)
  • Breaking change (a fix or feature that changes existing behavior)
  • Code quality, refactor, or test-only change
  • Documentation only

Additional information

  • This PR fixes or closes issue: fixes # None
  • This PR is related to: None
  • Link to a separate documentation pull request: None

Checklist

  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and poetry run pytest passes locally. A pull request cannot be merged unless CI is green.
  • poetry run prek run --all-files passes (lint, format, and type checks).
  • No commented-out or dead code is left in the pull request.

countries() pages locally, so a negative limit or offset went straight
into list slicing and returned the wrong countries. Refuse negative values
in every list method before sending a request.
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Oct 1, 2026
@frenck
frenck merged commit 71ec0cb into main Oct 1, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant