-
-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
Hi!
I have the following experiment, which works exactly as expected 🎉 :
Both webhooks_service and body get injected 👍
# main.py
@webhooks_api.route("/exp2", methods=["POST"])
@inject
def my_webhook2(
webhooks_service: WebhookService = Depends(get_webhook_service),
body: WebhookRequest = Validate(),
):
webhooks_service.process_webhook(body.payload)
return "Webhook processed successfully"However, during tests, when trying to override the get_webhook_service dependency:
class FakeWebhookService(WebhookService):
def process_webhook(self, payload):
print("Fake processing webhook:", payload)
def get_fake_webhook_service():
return FakeWebhookService()
@pytest.fixture
def test_app():
flask_app = create_app()
# Override the dependency
dependency_provider.override(get_webhook_service, get_fake_webhook_service)
# or
# dependency_provider.dependency_overrides[original_dependency] = override_dependency
with flask_app.test_client() as test_client:
yield test_client
def test_dependency_overriding_exp2(test_app):
# Exp2: Uses Annotated
res = test_app.post("/exp2", json={"payload": {"foo": "bar"}})
assert res.status_code == 200, res.dataI get the following error:
Error: pydantic_core._pydantic_core.ValidationError: 1 validation error for my_webhook2
webhooks_service
Input should be an instance of WebhookService [type=is_instance_of, input_value=<test_app_3_fastdepends.g...bject at 0xffff9bc4eaa0>, input_type=get_fake_webhook_service.<locals>.FakeWebhookService]
For further information visit https://errors.pydantic.dev/2.9/v/is_instance_of
NB: I noticed that the same issue doesn't happen on FastAPI.
Metadata
Metadata
Assignees
Labels
No labels