-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
linkcheck only emits warnings on HTTP redirects if linkcheck_allowed_redirects
is non-empty
#13439
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
Comments
Thank you for the detailed report James (nice to see a fellow economist!). The relevant code is: sphinx/sphinx/builders/linkcheck.py Lines 181 to 187 in 457754b
This behaviour was originally introduced in #9234 (#6525). The PR seems to have first sought to introduce cc @jayaddison, what do you think about this? My immediate reaction is that changing to fail on any redirects by default would be more annoying than helpful, but equally needing to specify a non-empty dict isn't helpful. A simple 'fix' would be to allow setting A |
Thanks very much for the quick, thoughtful, and informative response!
From my perspective as a (new!) user of the It wouldn't be that annoying to me:
That said, I understand that changing this behavior at this stage could be disruptive for folks, and I know how stressful it is to have someone newly show up in your repo asking for breaking changes 😅 . Any mechanism that reserved a special value or provided new configuration options to achieve "warn on all redirects" would be an improvement over needing to provide a placeholder like |
Thanks both! A couple of questions I infer from this are:
If we can answer those, I think we can choose an appropriate default behaviour and config value. My personal opinions are:
|
Note / slightly off-topic: I do think including text output related to bugreports is generally preferable to providing screenshots; it can be more accessible, for example, and is easier to search. |
I agree. Like I mentioned, here I included screenshots specifically because Here are the full logs: without linkcheck_allowed_redirects defined (click me)
with linkcheck_allowed_redirects set and non-empty (click me)
|
Thanks @jameslamb! @AA-Turner would it be outlandish to suggest using (from some very unscientific testing using Py3.13, |
Sorry for the slight delay here. I've opened #13452 as a sketch solution. Notably, the only uses of A |
Thanks very much! I can't say much about the specific implementation because I'm not that familiar with Sphinx's internals, but I'd be very happy with this interface change. Having to opt in to all-redirects-are-warnings by setting |
@AA-Turner @jameslamb FYI: I'm likely to open a follow-up pull request for #13452, because we have encountered a regression for The logic I currently have in mind is:
I have a concern that although we are focusing on the edge cases (the empty dict and |
A modification to this plan:
Because we would prefer to disallow The ergonomics of importing |
Describe the bug
The docs for led me to believe that HTTP redirects would result in warnings from the
linkcheck
builder, which I could then turn into a non-0 exit status (and therefore CI failures) via--fail-on-warning
.(my emphasis)
ref: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-linkcheck_allowed_redirects
I found that if
linkcheck_allowed_redirects
is empty or not specific inconf.py
, HTTP redirects are reported in log output but not emitted as warnings.As a result, redirects could silently make it through the
linkcheck
check. To work around this, I'm defining a placeholder like this to get the behavior "fail on any redirects".How to Reproduce
With
sphinx
8.2.3, installed fromconda-forge
, ran the quickstart.mkdir testproject cd ./testproject sphinx-quickstart \ --no-sep \ --project testproject \ --author james \ --release v0.1.0 \ --language en docs
Added a link that's guaranteed to redirect into
index.rst
.(you can test this yourself with
curl -i https://httpbin.org/redirect/1
)Saw
linkcheck
report the redirect in logs, but return a 0 exit status.Including a screenshot instead of text only because I think that the output color indicates something about the type of log message
sphinx
is omitting (a difference I don't understand, sorry).Added a nonsense
linkcheck_allowed_redirects
.And tried again. This time, saw the redirect reported as a warning (in red this time), an a non-0 exit status.
Environment Information
output of 'python -m sphinx --bug-report' (click me)
Sphinx extensions
None
Additional context
I'm reporting this as a "bug" because it seems based on the docs that this is unintentional. But if it is intentional, I'd be happy to submit a PR proposing a clarification to those docs explaining how to achieve "fail on any redirects".
I did look for other relevant issues and didn't find any specifically about this. Linking a few somewhat-related:
linkcheck_allowed_redirects
(Link checker should be able to prohibit unknown redirects #6525)Thanks for your time and consideration.
The text was updated successfully, but these errors were encountered: