Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add limit and max_age params to RSS feeds #7117

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexbecker
Copy link

Implements #7116, introducing limit and max_age query parameters to the packages.xml and releases.xml feeds. The limit parameter controls how many items are returned, defaulting to 40 if not present (same as current behavior) and respecting values up to 200 (an arbitrary maximum I chose, please suggest a more appropriate value). The max_age query parameter filters down to items at most max_age seconds old; I chose to use seconds of age instead of datetimes/timestamps in the request because they are easier to parse (unless I used unix timestamps, I suppose) and less sensitive to clock skew.

Creates a small _get_int_query_param utility to parse these parameters and 400 if they are not valid integers. Please let me know if there is an existing utility I should use or if I should move this to the utils module.

Currently limit requests over MAX_RESULTS (200) are silently reduced to returning MAX_RESULTS items. Should this be changed to a 400 error?

Thank you for maintaining PyPI and thanks in advance for your time reviewing this PR!

Copy link
Contributor

@yeraydiazdiaz yeraydiazdiaz left a comment

Choose a reason for hiding this comment

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

Thanks for this @alexbecker 🌟

LGTM just left a minor comment and some nits. 👍

tests/unit/rss/test_views.py Show resolved Hide resolved
# Return default if 'param' is absent or has an empty value.
return default
try:
return int(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it'd be worth asserting it must be a positive integer as well?

MAX_RESULTS = 200


def _get_int_query_param(request, param, default=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I feel defaulting to None might be dangerous here as the caller might expect an integer. The two options I see is raising an expection or returning a sentinel value (maybe -1 or 0 would make sense?).

@di
Copy link
Member

di commented Jan 2, 2020

I think we probably need a bit more discussion before continuing work on this, see #7116 (comment).

Base automatically changed from master to main January 21, 2021 18:39
@miketheman miketheman added the needs discussion a product management/policy issue maintainers and users should discuss label Jun 26, 2023
@alexbecker alexbecker requested a review from a team as a code owner February 22, 2024 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APIs/feeds needs discussion a product management/policy issue maintainers and users should discuss
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants