Skip to content

Commit

Permalink
Merge pull request #731 from arXiv/develop
Browse files Browse the repository at this point in the history
fix 500 for alias redirects
  • Loading branch information
kyokukou authored Sep 20, 2024
2 parents 5207802 + 76207e6 commit a953641
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 4 additions & 5 deletions browse/controllers/catchup_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ def get_catchup_page(subject_str:str, date:str)-> Response:
subject, start_day, include_abs, page=_process_catchup_params(subject_str, date)
#check for redirects for noncanon subjects
if subject.id != subject.canonical_id:
return redirect(
url_for('catchup',
new_address=url_for('browse.catchup',
subject=subject.canonical_id,
date=start_day,
page=page,
abs=include_abs),
HTTPStatus.MOVED_PERMANENTLY) #type: ignore
abs=include_abs)
return {}, HTTPStatus.MOVED_PERMANENTLY, {"Location":new_address}

headers: Dict[str,str]={}
headers=add_surrogate_key(headers,["catchup",f"list-{start_day.year:04d}-{start_day.month:02d}-{subject.id}"])
#get data
Expand Down
12 changes: 11 additions & 1 deletion tests/test_catchup.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,14 @@ def test_catchup_form_redirect(dbclient):
assert 'Surrogate-Key' in resp.headers
header= resp.headers['Surrogate-Key']
assert " catchup " in " "+header+" "
assert " catchup-redirect " in " "+header+" "
assert " catchup-redirect " in " "+header+" "

def test_catchup_alias_redirect(dbclient):
with patch('browse.controllers.catchup_page.datetime') as mock_datetime:
mock_datetime.now.return_value = datetime(2011, 2, 15)
mock_datetime.date = datetime.date
mock_datetime.strptime = datetime.strptime
resp = dbclient.get("/catchup/math.MP/2011-02-03?page=1")
assert resp.status_code ==301
redirect_location = resp.headers.get("Location")
assert redirect_location == "/catchup/math-ph/2011-02-03?page=1&abs=False"

0 comments on commit a953641

Please sign in to comment.