Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: <class>.<func> got multiple values for argument '<arg>' #867

Open
kepeder opened this issue Mar 4, 2025 · 0 comments
Open

TypeError: <class>.<func> got multiple values for argument '<arg>' #867

kepeder opened this issue Mar 4, 2025 · 0 comments

Comments

@kepeder
Copy link

kepeder commented Mar 4, 2025

Updating dependency-injector from dependency-injector==4.45.0 to dependency-injector==4.46.0 makes the application crash with multiple values for argument.

Expected Behavior

Same behavior as in v4.45.0.

Current Behavior

Steps to Reproduce

  • containers/application.py:
from dependency_injector.containers import DeclarativeContainer
from dependency_injector.providers import Container, ThreadLocalSingleton

from config import Configuration

from .services import Services


class Application(DeclarativeContainer):
    ...
    configuration = ThreadLocalSingleton[Configuration](Configuration)

    services: Container[Services] = Container[Services](Services, configuration=configuration)
  • containers/repositories.py:
from dependency_injector.containers import DeclarativeContainer, WiringConfiguration
from dependency_injector.providers import Factory, ThreadLocalSingleton

from config import Configuration
from repositories import TranslationValueRepository

from .gateways import Gateways

class Repositories(DeclarativeContainer):
    wiring_config = WiringConfiguration(
        packages=[
            "services",
            "abstracts.services",
        ]
    )

    ...
    configuration = ThreadLocalSingleton[Configuration](Configuration)

    translation_value_repository = Factory(lambda: TranslationValueRepository(...))
    ....
  • abstracts/services/translation_scheme_values_service.py:
from abc import ABC, ABCMeta
from uuid import UUID

from dependency_injector.wiring import Provide, inject

from containers.repositories import Repositories
from models.api import SchemaNameTranslation
from repositories import TranslationValueRepository


class TranslationSchemeValuesServiceAbstract(ABC, metaclass=ABCMeta):
    @staticmethod
    @inject
    def get_translation_scheme_values(
        translation_id: UUID,
        translation_value_repository: TranslationValueRepository = Provide[Repositories.translation_value_repository],
    ) -> list[SchemaNameTranslation]:
        translation_values = translation_value_repository.get_by_translation_id(translation_id)

        return TranslationSchemeValuesServiceAbstract.transform_translation_scheme_values(translation_values)

Then we have a service which inherits this Abstract class and using the function get_translation_scheme_values which again throws the exception which is detailed below.

Context (Environment)

Python 3.13.1

Packages list:

❯ pip list                               
Package                  Version
------------------------ -----------------
alembic                  1.14.1
annotated-types          0.7.0
anyio                    4.8.0
artifacts-keyring        0.4.0
asgi-correlation-id      4.3.4
attrs                    25.1.0
azure-core               1.32.0
azure-identity           1.20.0
azure-storage-blob       12.24.1
azure-storage-file-share 12.20.1
bcrypt                   4.3.0
black                    25.1.0
Brotli                   1.1.0
build                    1.2.2.post1
certifi                  2025.1.31
cffi                     1.17.1
cfgv                     3.4.0
chardet                  5.2.0
charset-normalizer       3.4.1
click                    8.1.8
coverage                 7.6.12
cryptography             44.0.2
cssselect2               0.7.0
dependency-injector      4.46.0
distlib                  0.3.9
dlint                    0.16.0
dnspython                2.7.0
email_validator          2.2.0
execnet                  2.1.1
fastapi                  0.115.11
filelock                 3.17.0
flake8                   7.1.2
flake8-async             25.2.3
flake8-bugbear           24.12.12
flake8-isort             6.1.2
flake8-mutable           1.2.0
h11                      0.14.0
httpcore                 1.0.7
httpx                    0.28.1
identify                 2.6.8
idna                     3.10
iniconfig                2.0.0
isodate                  0.7.2
isort                    6.0.1
jaraco.classes           3.4.0
jaraco.context           6.0.1
jaraco.functools         4.1.0
jwcrypto                 1.5.6
keyring                  25.6.0
libcst                   1.6.0
lxml                     5.3.1
Mako                     1.3.9
MarkupSafe               3.0.2
mccabe                   0.7.0
more-itertools           10.6.0
msal                     1.31.1
msal-extensions          1.2.0
mypy                     1.15.0
mypy-extensions          1.0.0
mysql-connector-python   9.2.0
nodeenv                  1.9.1
packaging                24.2
pathspec                 0.12.1
pika                     1.3.2
pillow                   11.1.0
pip                      24.2
pip-check-reqs           2.5.3
pip-tools                7.4.1
platformdirs             4.3.6
pluggy                   1.5.0
portalocker              2.10.1
pre_commit               4.1.0
psutil                   7.0.0
puremagic                1.28
pycodestyle              2.12.1
pycparser                2.22
pydantic                 2.10.6
pydantic_core            2.27.2
pydantic-extra-types     2.10.2
pydantic-settings        2.8.1
pyflakes                 3.2.0
PyJWT                    2.10.1
pyproject_hooks          1.2.0
pytest                   8.3.5
pytest-asyncio           0.25.3
pytest-cov               6.0.0
pytest-split             0.10.0
pytest-xdist             3.6.1
python-dotenv            1.0.1
python-multipart         0.0.20
pytz                     2025.1
PyYAML                   6.0.2
redis                    5.2.1
reportlab                4.3.1
requests                 2.32.3
requests-toolbelt        1.0.0
setuptools               75.8.0
six                      1.17.0
sniffio                  1.3.1
SQLAlchemy               2.0.38
starlette                0.46.0
structlog                25.1.0
svglib                   1.5.1
tinycss2                 1.4.0
typeguard                4.4.2
types-cachetools         5.5.0.20240820
types-mock               5.1.0.20240425
types-pika               1.2.0b1
types-pytz               2025.1.0.20250204
types-PyYAML             6.0.12.20241230
types-requests           2.32.0.20250301
typing_extensions        4.12.2
urllib3                  2.3.0
uvicorn                  0.34.0
virtualenv               20.29.2
webencodings             0.5.1
wheel                    0.45.1

Detailed Description

ERROR    root:error_handling.py:225 TranslationSchemeValuesServiceAbstract.get_translation_scheme_values() got multiple values for argument 'translation_value_repository'
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/asgi_correlation_id/middleware.py", line 90, in __call__
    await self.app(scope, receive, handle_outgoing_request)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/applicationlib/python3.13/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/routing.py", line 714, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/routing.py", line 734, in app
    await route.handle(scope, receive, send)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
               ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/fastapi/routing.py", line 301, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/dependency_injector/wiring.py", line 1040, in _patched
    return await _async_inject(
           ^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
    )
    ^
  File "src/dependency_injector/_cwiring.pyx", line 61, in _async_inject
  File "/Users/<user>/.../application/controllers/tenant.py", line 132, in create_tenant
    tenant = create_tenant_service.create_tenant(
        body.slug,
    ...<5 lines>...
        authentication=authentication,
    )
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/dependency_injector/wiring.py", line 1054, in _patched
    return _sync_inject(
        fn,
    ...<3 lines>...
        patched.closing,
    )
  File "src/dependency_injector/_cwiring.pyx", line 24, in dependency_injector._cwiring._sync_inject
  File "/Users/<user>/.../application/services/create_tenant_service.py", line 95, in create_tenant
    permission_schema = self.populate_permission(permission)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/dependency_injector/wiring.py", line 1054, in _patched
    return _sync_inject(
        fn,
    ...<3 lines>...
        patched.closing,
    )
  File "src/dependency_injector/_cwiring.pyx", line 24, in dependency_injector._cwiring._sync_inject
  File "/Users/<user>/.../application/abstracts/services/permission_service.py", line 24, in populate_permission
    description_translations = self.get_translation_scheme_values(permission.translation_id)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/application/lib/python3.13/site-packages/dependency_injector/wiring.py", line 1054, in _patched
    return _sync_inject(
        fn,
    ...<3 lines>...
        patched.closing,
    )
  File "src/dependency_injector/_cwiring.pyx", line 24, in dependency_injector._cwiring._sync_inject
TypeError: TranslationSchemeValuesServiceAbstract.get_translation_scheme_values() got multiple values for argument 'translation_value_repository'

Possible Implementation

Expected behaviour: Since it works with dependency-injector==4.45.0, I'd expect it to work the same.
Actual behaviour: Crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant