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

Fix pagination when listing discussions #1962

Merged
merged 2 commits into from
Jan 9, 2024
Merged

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Jan 8, 2024

Pagination in get_repo_discussions is broken which leads to an infinite loop on repos with more than 50 discussions. This PR fixes this. Pagination is page-based (not cursor-based as other listing APIs) and the page parameter is named "p" server-side, not "page_index" (see in moon-landing -private repo-).

I encountered this issue while listing discussions on the Open LLM Leaderboard (cc @clefourrier).

# infinite loop before, now fixed by this PR
for d in get_repo_discussions(repo_id="HuggingFaceH4/open_llm_leaderboard", repo_type="space"):
    print(d.title)

I also made a small change to use requests.get(..., params=...) instead of urlencode.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link

codecov bot commented Jan 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fc2be44) 82.32% compared to head (d8004df) 82.38%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1962      +/-   ##
==========================================
+ Coverage   82.32%   82.38%   +0.06%     
==========================================
  Files          66       66              
  Lines        8141     8141              
==========================================
+ Hits         6702     6707       +5     
+ Misses       1439     1434       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Great, thanks @Wauplin!

Comment on lines +2473 to +2478
@with_production_testing
def test_get_repo_discussion_pagination(self):
discussions = list(
HfApi().get_repo_discussions(repo_id="HuggingFaceH4/open_llm_leaderboard", repo_type="space")
)
assert len(discussions) > 50
Copy link
Member

Choose a reason for hiding this comment

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

Heavy test 😅

@Wauplin
Copy link
Contributor Author

Wauplin commented Jan 9, 2024

Thanks for the review!

@Wauplin Wauplin merged commit 7c74445 into main Jan 9, 2024
16 checks passed
@Wauplin Wauplin deleted the fix-paginate-over-discussions branch January 9, 2024 09:32
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.

None yet

3 participants