Skip to content

Pass the configured botname to NotifyMattermost - #23281

Merged
desertaxle merged 2 commits into
PrefectHQ:mainfrom
Ayoubhm07:fix/mattermost-botname
Oct 5, 2026
Merged

desertaxle merged 2 commits into
PrefectHQ:mainfrom
Ayoubhm07:fix/mattermost-botname

Conversation

@Ayoubhm07

@Ayoubhm07 Ayoubhm07 commented Oct 4, 2026 •

Copy link
Copy Markdown

closes #23282
MattermostWebhook exposes a botname field, but block_initialization never passes it to NotifyMattermost. The name is accepted by pydantic, persisted on the block document, then dropped at send time no exception, no warning, no log line.

$ grep -rn "botname" src/ --include='*.py'
src/prefect/blocks/notifications.py:709:    botname: Optional[str] = Field(     # Mattermost, declared
src/prefect/blocks/notifications.py:811:    botname: Optional[str] = Field(     # Discord, declared
src/prefect/blocks/notifications.py:863:                botname=self.botname,   # Discord, passed

In webhook mode the default, and the only mode this block can reach since it does not expose mode apprise builds the sender name as payload["username"] = self.user if self.user else self.app_id (apprise/plugins/mattermost.py:646). With self.user unset, every message is signed with the asset name instead of the configured one.

How it regressed

#19780 set user=self.botname on this exact call. block_initialization was later rewritten to add the plugin instance directly instead of going through .url(), because apprise >= 1.9.9 stopped putting channels in the URL and renamed channels to targets. That rewrite kept seven of the eight fields and left user=self.botname behind. The comment above the call (notifications.py:747-749) documents the .url() and targets changes only.

Why user= and not botname=

NotifyMattermost.__init__ takes no botname keyword. apprise declares it as an alias of user (mattermost.py:225-227) and relays **kwargs to URLBase, which reads user. Passing botname= lands in **kwargs and is ignored the original bug #19780 fixed.

Verification

The added test, plus the existing test_notify_with_multiple_channels as a witness, run against the patched source and against the source with the one line removed:

line removed:  1 failed, 1 passed
               AssertionError: assert None == 'Prefect Bot'
line present:  2 passed

Driving the plugin directly with requests.post patched, no network and no server:

before:  plugin.user = None          payload['username'] = 'Apprise'
after:   plugin.user = 'Deploy Bot'  payload['username'] = 'Deploy Bot'

targets and port are unchanged in both.

The full TestMattermostWebhook class could not be run here: every test in it, including the five that predate this change, errors on RuntimeError: Timed out while attempting to connect to hosted test Prefect API (src/prefect/testing/fixtures.py:135). That is my environment, not this change, which is why the checks above were run outside the session fixture.

Measured with apprise==1.13.1 (the pin is apprise>=1.13.0,<2.0.0).

Noted while reproducing, out of scope

The fallback prints Apprise, not Prefect Notifications. Apprise.add() given an already constructed plugin instance just appends it (apprise/apprise.py:308-310) without applying the asset, so the AppriseAsset built at notifications.py:760-764 never reaches this plugin. Separate branding issue, untouched here happy to open a follow-up.

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
  • If this is a complex change, a maintainer has confirmed the proposed approach on the linked issue.
    • Not complex: one added line, no new field, option, or dependency.
  • If this pull request adds or changes functionality, it includes tests or explains why tests are not needed.
  • If this pull request changes user-facing behavior, it updates documentation or explains why documentation is not needed.
    • The existing botname description is what is being restored; it is already accurate.
  • If this pull request removes docs files, it includes redirect settings in mint.json. N/A
  • If this pull request adds functions or classes, it includes helpful docstrings. N/A

AI tools were used to find this defect and draft this description. I understand the change, I kept it to one line, and I validated it locally as described above.

MattermostWebhook declares a botname field and surfaces it in the UI block
form, but block_initialization stopped passing it when it was rewritten to add
the NotifyMattermost instance directly instead of going through .url(). Seven
of the eight fields survived that rewrite; user=self.botname did not.

With self.user unset, apprise falls back to the asset app_id when building the
webhook payload (apprise/plugins/mattermost.py:646), so every message is signed
with the asset name regardless of what the user configured. The field is
accepted, persisted, and then discarded with no exception, warning, or log.

The keyword is user= rather than botname=: NotifyMattermost does not take a
botname argument, it declares botname as an alias of user and relays **kwargs to
URLBase, which reads user. This restores what PrefectHQ#19780 established before the
rewrite.

Adds test_botname_is_passed_to_apprise to the existing TestMattermostWebhook
class.

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 2 potential issues.

Devin Review

token=self.token.get_secret_value(),
fullpath=self.path,
host=self.hostname,
user=self.botname,

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.

🔍 Bug fix lacks issue discussion

This bug fix has no linked issue, despite the issue-first rule in contribution guidance. The cited earlier PR fixed the original defect, not this regression.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread tests/blocks/test_notifications.py Resolved
@codspeed

codspeed Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 8 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing Ayoubhm07:fix/mattermost-botname (a4852c8) with main (2338265)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

The test read plugin.user, an apprise-internal attribute reached through the
block's private _apprise_client. The contribution guide asks for tests that
assert user-visible behavior rather than private implementation details.

It now patches requests.post and asserts on payload["username"], which is the
name Mattermost actually displays. Without the fix it fails with
assert 'Apprise' == 'Prefect Bot' instead of assert None == 'Prefect Bot'.
@github-actions github-actions Bot added the bug Something isn't working label Oct 5, 2026
@Ayoubhm07

Copy link
Copy Markdown
Author

Both points taken

Issue opened at #23282 and linked above : the contribution guide asks for one beyond a doc or typo fix and I read the PR template's "small fix" wording too narrowly

The test now patches requests.post and asserts on payload["username"] rather than plugin.user : without the fix it fails with assert 'Apprise' == 'Prefect Bot' which is the name Mattermost would actually display

On the red group from the first run : the two failures were in tests/test_assets.py and tests/test_flow_engine.py and neither file is touched here
Both landed on gw2 and both were downstream of RuntimeError: Cannot put items in a stopped service instance repeating through the captured logs until AssertingEventsClient had no events attribute and the task run was never persisted
That is what #23172 is still open against : #22995 #23083 #23172 #23247 and #23249 have all been aimed at it since August
Adding a test shifts the pytest-split boundaries so that group ran a different mix it is green on the current head

@desertaxle desertaxle 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.

LGTM!

@desertaxle
desertaxle merged commit 0477263 into PrefectHQ:main Oct 5, 2026
109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MattermostWebhook silently ignores the configured botname

2 participants