microsoft / microsoft/teams.py
System type invokes — custom handler runs alongside built-in default rather than replacing it?
- Dominant language
- Python
- Stars
- 65
- Forks
- 30
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 23
Description
[NOTE] - since writing this, I have switched stance, and TS and C# should both adopt what PY is doing.
## Question
When registering a custom `signin/failure` handler via `@app.on_signin_failure()`, both the custom handler and the built-in default handler execute. In TypeScript and C#, registering a custom handler for the same route replaces the default one.
Is this intentional behavior for the Python SDK? I noticed the Python SDK uses additive middleware-style routing where all matching handlers chain together, so this may be by design. But it means there's no way to suppress the default behavior for these types of invokes.
Note that this only applies to `type: system` invokes (e.g. `signin/verifyState`, `signin/tokenExchange`, `signin/failure`) where the SDK registers built-in default handlers, so the practical impact is narrow.
## Behavior comparison
In TypeScript, when a new route is added with the same name, the [router removes the existing route](https://github.com/microsoft/teams.ts/blob/main/packages/apps/src/router/router.ts#L29-L34) before adding the new one — so a custom `signin.failure` handler replaces the default.
In Python, [`on_signin_failure`](https://github.com/microsoft/teams.py/blob/main/packages/apps/src/microsoft_teams/apps/app_oauth.py#L30) adds the handler without removing the existing default, so both execute.
## Reproduction
```python
@app.on_signin_failure()
async def handle_signin_failure(ctx):
failure = ctx.activity.value
print(f"Custom handler: {failure.code} - {failure.message}")
await ctx.send("Sign-in failed. Please contact your admin.")
```
When `signin/failure` is received, both the built-in default handler (which logs a warning) and the custom handler above fire.
## Context
- Confirmed via live testing in Teams with a `resourcematchfailed` failure
- Currently documenting this as a Python-specific note in the user authentication guide
Contributor guide
Research direction
Start with the Python handler registration in packages/apps/microsoft_teams/apps/app_oauth.py and the user authentication guide referenced in the issue. Compare the linked TypeScript router behavior and the described Python behavior, then clarify the intended system-invoke handler semantics in the documentation. Done means the guide accurately explains custom-handler and built-in-handler behavior and its limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, python, typescript
- Domain
- authentication, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100