Skip to content

Commit

Permalink
Merge pull request #216 from IvanKirpichnikov/fix-duplicate-param
Browse files Browse the repository at this point in the history
fixed duplicate container parameter
  • Loading branch information
Tishka17 authored Aug 18, 2024
2 parents a11354b + 7ed1713 commit 45bb6c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/dishka/integrations/aiogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
]

from collections.abc import Awaitable, Callable, Container
from inspect import Parameter
from inspect import Parameter, signature
from typing import Any, Final, ParamSpec, TypeVar, cast

from aiogram import BaseMiddleware, Router
Expand All @@ -23,11 +23,14 @@


def inject(func: Callable[P, T]) -> Callable[P, T]:
additional_params = [Parameter(
name=CONTAINER_NAME,
annotation=Container,
kind=Parameter.KEYWORD_ONLY,
)]
if CONTAINER_NAME in signature(func).parameters:
additional_params = []
else:
additional_params = [Parameter(
name=CONTAINER_NAME,
annotation=Container,
kind=Parameter.KEYWORD_ONLY,
)]

return wrap_injection(
func=func,
Expand Down
15 changes: 14 additions & 1 deletion tests/integrations/aiogram/test_aiogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from aiogram import Dispatcher
from aiogram.types import Chat, Message, Update, User

from dishka import make_async_container
from dishka import AsyncContainer, make_async_container
from dishka.integrations.aiogram import FromDishka, inject, setup_dishka
from ..common import (
APP_DEP_VALUE,
Expand Down Expand Up @@ -107,3 +107,16 @@ async def test_request_dependency2(bot, app_provider: AppProvider):
await send_message(bot, dp)
app_provider.mock.assert_called_with(REQUEST_DEP_VALUE)
app_provider.request_released.assert_called_once()


async def handle_get_async_container(
_: Message,
dishka_container: AsyncContainer,
) -> None:
assert isinstance(dishka_container, AsyncContainer)


@pytest.mark.asyncio
async def test_get_async_container(bot, app_provider: AppProvider):
async with dishka_app(handle_get_async_container, app_provider) as dp:
await send_message(bot, dp)

0 comments on commit 45bb6c2

Please sign in to comment.