Fury0508 opened a new pull request, #61103:
URL: https://github.com/apache/airflow/pull/61103
## Description
Fixes protocol validation bug in `KiotaRequestAdapterHook` that caused
`PowerBIDatasetRefreshOperator` to fail with `httpx.UnsupportedProtocol:
Request URL is missing an 'http://' or 'https://' protocol` error.
### Root Cause
The hook had two bugs introduced in PR #45006:
1. **Logic bug in `get_host()` method (line 238)**: Used `or` instead of
tuple check
```python
# BROKEN - always evaluates to True for URLs with https://
if not self.host.startswith("http://") or not
self.host.startswith("https://"):
return f"{connection.schema}://{self.host}"
# Result: "https://https://api.powerbi.com" ❌
```
2. **Missing protocol validation**: `__init__` set `self.host` directly
without ensuring protocol prefix
### Changes
- Added `_ensure_protocol()` method to validate and add protocol prefix when
missing
- Fixed logic bug in `get_host()` - changed `or` to proper tuple check with
`startswith(("http://", "https://"))`
- Added safety fallback (`schema or "https"`) when `connection.schema` is
None
- Added comprehensive test class `TestKiotaRequestAdapterHookProtocol` with
10 test cases covering all protocol scenarios
### Testing
- All 10 new tests pass
- Existing msgraph tests continue to pass
- Verified fix resolves the exact error scenario from issue #61081
closes: #61081
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude (Anthropic) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
**AI Assistance Details:**
- Used to understand root cause location by analyzing the codebase and error
trace
- Used to write comprehensive test code
(`TestKiotaRequestAdapterHookProtocol` class with 10 test cases)
- Used to suggest fail-safe options
- Final implementation and code review done by human contributor
---
**Checklist:**
- [X] Code changes are covered with tests
- [X] All tests pass locally
- [X] Pre-commit checks pass (`prek run --all-files`)
- [X] Follows commit message guidelines
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]