Skip to content

Warn on all redirects if linkcheck_allowed_redirects is an empty dictionary #13452

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

Merged
merged 3 commits into from
Mar 27, 2025

Conversation

AA-Turner
Copy link
Member

@AA-Turner AA-Turner merged commit 3c4b4e3 into sphinx-doc:master Mar 27, 2025
23 checks passed
@AA-Turner AA-Turner deleted the linkcheck-warn-all-redirects branch March 27, 2025 19:03
config.linkcheck_allowed_redirects = None
return
if not isinstance(config.linkcheck_allowed_redirects, dict):
raise ConfigError
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing an explanatory message here?

@jayaddison
Copy link
Contributor

Perhaps we should update the default linkcheck_allowed_redirects value in the documentation to None? (since it's not really a default of an empty-dict anymore)

@@ -178,7 +179,7 @@ def process_result(self, result: CheckResult) -> None:
text = 'with unknown code'
linkstat['text'] = text
redirection = f'{text} to {result.message}'
if self.config.linkcheck_allowed_redirects:
if self.config.linkcheck_allowed_redirects is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

This line/diff is confusing without context -- but the way I understand this: this code is within the _Status.REDIRECTED case -- and we can only reach this part of the code if a disallowed redirect occurred, or if no filtering of allowed redirects is configured. So the conditional check here is a shortcut, simply confirming whether allowed redirects are configured or not; if it is configured, we should emit a warning.

Copy link
Contributor

@jayaddison jayaddison left a comment

Choose a reason for hiding this comment

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

Generally looks good to me. I'll open a pull request with the two nitpicky suggestions I had (an update default in the config docs, and an exception message).

@pllim
Copy link

pllim commented Apr 1, 2025

Hi. Is it possible that this PR introduced a regression? We see a new failure at astropy/sphinx-astropy#80 for sphinx-dev but we have no changed anything related to linkcheck lately.

The only specific linkcheck setting we touch is this at https://github.com./astropy/sphinx-astropy/blob/9ee5275a8ccc09f434dc54f66993dbd0356d7200/sphinx_astropy/conf/v2.py#L386

linkcheck_timeout = 60

So the warning below is unexpected unless I missed something?

WARNING: The config value `linkcheck_allowed_redirects' has type `NoneType'; expected `dict'.

Hope you can advise. Thanks!

@jayaddison
Copy link
Contributor

Thanks @pllim for reporting this - that does seem likely to be related to this pull request, yep. I would have expected the config to use the default sentinel value for linkcheck_allowed_redirects added in this PR; for some reason it appears that was not the case. Would you mind opening an issue report for this?

@pllim
Copy link

pllim commented Apr 2, 2025

Thank you for your reply. I opened #13462

@jayaddison
Copy link
Contributor

Thanks @pllim - I'll aim to investigate that within the next day or two.

@jayaddison
Copy link
Contributor

Note: two of our existing linkcheck test cases pass somewhat-by-quirk, following this PR; they are:

  • tests/test_builders/test_build_linkcheck.py::test_follows_redirects_on_HEAD
  • tests/test_builders/test_build_linkcheck.py::test_follows_redirects_on_GET

Patching them so that compile_linkcheck_allowed_redirects is invoked -- as it is when a genuine sphinx-build takes place, results in them failing.

--- a/tests/test_builders/test_build_linkcheck.py
+++ b/tests/test_builders/test_build_linkcheck.py
@@ -712,6 +712,7 @@ def log_date_time_string(self):
 )
 def test_follows_redirects_on_HEAD(app, capsys):
     with serve_application(app, make_redirect_handler(support_head=True)) as address:
+        compile_linkcheck_allowed_redirects(app, app.config)
         app.build()
     _stdout, stderr = capsys.readouterr()
     content = (app.outdir / 'output.txt').read_text(encoding='utf8')
@@ -735,6 +736,7 @@ def test_follows_redirects_on_HEAD(app, capsys):
 )
 def test_follows_redirects_on_GET(app, capsys):
     with serve_application(app, make_redirect_handler(support_head=False)) as address:
+        compile_linkcheck_allowed_redirects(app, app.config)
         app.build()
     _stdout, stderr = capsys.readouterr()
     content = (app.outdir / 'output.txt').read_text(encoding='utf8')

That's a rough edge in the existing linkcheck builder testsuite -- ideally we'd not require test authors to include that step themselves (it can easily be omitted).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants