Repository navigation
Closed
Description
Summary
The Draft.draftPicks() and Draft.draftProspects() methods ignore the year parameter and always return the current year's draft data regardless of what year is requested.
Bug Details
Root Cause
The path parameter year is defined in the endpoint schema as a required path parameter, but the path template is /v1/draft without a {year} placeholder. This causes the library to ignore the year parameter when constructing the URL.
Expected URL: https://statsapi.mlb.com/api/v1/draft/2020
Actual URL: https://statsapi.mlb.com/api/v1/draft
Reproduction
from pymlb_statsapi import api
import httpx
# pymlb_statsapi ignores year parameter
resp = api.Draft.draftPicks(year=2020)
print("URL:", resp.url) # https://statsapi.mlb.com/api/v1/draft (missing /2020)
data = resp.json()
print("Requested year: 2020")
print("Returned draftYear:", data['drafts']['draftYear']) # Returns 2025 (current year)
# Direct API call with correct URL works
with httpx.Client() as client:
resp = client.get("https://statsapi.mlb.com/api/v1/draft/2020")
data = resp.json()
print("Direct call draftYear:", data['drafts']['draftYear']) # Returns 2020Output:
URL: https://statsapi.mlb.com/api/v1/draft
Requested year: 2020
Returned draftYear: 2025
Direct call draftYear: 2020
Method Info
api.Draft.get_method_info('draftPicks'){
'name': 'draftPicks',
'path': '/v1/draft', # BUG: Missing {year} placeholder
'http_method': 'GET',
'path_params': [{
'name': 'year',
'paramType': 'path', # Marked as path param
'required': True, # Required
'description': 'Year the player was drafted. Format: 2000'
}],
...
}Affected Methods
| Method | Expected Path | Actual Path |
|---|---|---|
Draft.draftPicks(year=YYYY) |
/v1/draft/{year} |
/v1/draft |
Draft.draftProspects(year=YYYY) |
/v1/draft/prospects/{year} |
/v1/draft/prospects |
Draft.latestDraftPicks() |
/v1/draft |
/v1/draft (correct) |
Proposed Fix
Update the endpoint schema for Draft to include {year} in the path template:
Current (Broken)
{
"path": "/v1/draft",
"operations": [{
"nickname": "draftPicks",
"parameters": [{
"name": "year",
"paramType": "path",
"required": true
}]
}]
}Fixed
{
"path": "/v1/draft/{year}",
"operations": [{
"nickname": "draftPicks",
"parameters": [{
"name": "year",
"paramType": "path",
"required": true
}]
}]
}And similarly for draftProspects:
- Current:
/v1/draft/prospects - Fixed:
/v1/draft/prospects/{year}
Impact
- Historical data retrieval broken: Cannot fetch draft data from past years
- Data integrity risk: Users may unknowingly receive wrong year's data
Workaround
Use direct HTTP requests with the correct URL:
import httpx
draft_year = 2024
url = f"https://statsapi.mlb.com/api/v1/draft/{draft_year}"
with httpx.Client() as client:
resp = client.get(url)
data = resp.json()Discovered while building mlb_statsapi_data_platform.
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix: Draft.draftPicks() now correctly uses year parameter in URL path