Skip to content

Fix parse_lpo_and_dwpp not raising ValueError when disable_web_page_preview=False#5268

Merged
harshil21 merged 3 commits into
python-telegram-bot:masterfrom
JSap0914:fix-parse-lpo-false-not-exclusive
Jun 17, 2026
Merged

Fix parse_lpo_and_dwpp not raising ValueError when disable_web_page_preview=False#5268
harshil21 merged 3 commits into
python-telegram-bot:masterfrom
JSap0914:fix-parse-lpo-false-not-exclusive

Conversation

@JSap0914

Copy link
Copy Markdown
Contributor

Bug

parse_lpo_and_dwpp is documented to raise ValueError when both
disable_web_page_preview and link_preview_options are supplied
(they are mutually exclusive). However, when disable_web_page_preview=False
the guard used a truthy check:

if disable_web_page_preview and link_preview_options:

False and X short-circuits to False, so no ValueError is raised.
The code then falls through to the second condition:

if disable_web_page_preview is not None:
    link_preview_options = LinkPreviewOptions(is_disabled=disable_web_page_preview)

which silently overwrites the caller's link_preview_options with
LinkPreviewOptions(is_disabled=False), discarding the user-supplied value.

Fix

Change the guard to is not None so any explicit bool value triggers the
mutual-exclusivity check:

if disable_web_page_preview is not None and link_preview_options:

Verification

pytest tests/_inline/test_inputtextmessagecontent.py -v

Before fix: test_mutually_exclusive passes only the True sub-case; the new
False sub-case fails (ValueError is not raised).

After fix: all 7 tests in the file pass.

AI-assisted: this change was prepared with the help of an AI coding assistant.

When disable_web_page_preview=False (explicitly enabling previews) was
passed alongside link_preview_options, the mutual-exclusivity guard:

    if disable_web_page_preview and link_preview_options:

evaluated to False (short-circuit), so no ValueError was raised.
Instead, the user's link_preview_options was silently overwritten with
LinkPreviewOptions(is_disabled=False), discarding their value.

Fix: use 'is not None' to check for any explicit non-None value.

Regression: add the False case to test_mutually_exclusive.
Copilot AI review requested due to automatic review settings June 17, 2026 08:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@harshil21 harshil21 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the very subtle bug catch. This didn't have any bad effects since None-ness is still falsy, so it worked just fine. But yes, it's important to have correctness.

Comment thread changes/unreleased/5268.GKZnfBkMcLqBC4rTgznsnY.toml Outdated
@JSap0914

Copy link
Copy Markdown
Contributor Author

Thanks @harshil21 — applied your suggestion; the chango fragment now uses double backticks for all identifiers.

@harshil21 harshil21 merged commit 35810fe into python-telegram-bot:master Jun 17, 2026
25 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants