Fix anchor validation silently disabled when verbose mode is active - #4160
Open
amitmishra11 wants to merge 1 commit into
Open
amitmishra11 wants to merge 1 commit into
amitmishra11 wants to merge 1 commit into
Conversation
render() gated anchor-link collection on log.getEffectiveLevel() > logging.DEBUG, which meant enabling verbose mode (which sets the logger to DEBUG) caused self.links_to_anchors to remain None, silently skipping all anchor validation. The result: mkdocs build --strict would abort, but mkdocs build -v --strict would succeed and exit 0 regardless of configured anchor warnings. Fix: check config.validation.links.anchors > logging.DEBUG instead. This preserves the intended skip when validation.links.anchors is 'ignore' (mapped to DEBUG), while remaining unaffected by the runtime logger level. Adds a regression test that sets the mkdocs logger to DEBUG before build and verifies anchor warnings still fire. Fixes mkdocs#3991
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3991.
Bug
Page.render()gated anchor-link collection onlog.getEffectiveLevel() > logging.DEBUG. When verbose mode (mkdocs build -v) is active the MkDocs logger is set toDEBUG, so that condition becomesFalse,self.links_to_anchorsstaysNone, andvalidate_anchor_linkssilently returns early.The observable consequence:
mkdocs build --strictaborts due to anchor warnings, butmkdocs build -v --strictsucceeds with exit code 0 despite those same warnings being configured.Root cause analysis
The intent was to skip expensive anchor-link collection when the
validation.links.anchorsconfig isignore(which maps tologging.DEBUG). The implementation usedlog.getEffectiveLevel()as a proxy for that config value, but they are not equivalent. The verbose flag affects the runtime log level independently of the configured validation severity.Fix
Replace the runtime log-level check with a check against the configured validation level:
This skips anchor-link collection only when the user has explicitly set
validation.links.anchors: ignore, and is unaffected by whether verbose mode is active.Testing
Added
test_anchor_warning_not_suppressed_in_verbose_modewhich sets the mkdocs logger toDEBUGbefore callingbuild.build()and asserts that anchor warnings are still emitted. All 6 anchor-related tests pass.