Skip to content

[BUG] all async test routers failed with TypeError: 'list' object is not callable #1440

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

Open
tim-hub opened this issue Apr 9, 2025 · 4 comments

Comments

@tim-hub
Copy link
Contributor

tim-hub commented Apr 9, 2025

Describe the bug
all async test routers failed with

 TypeError: 'list' object is not callable

Everything was fine on 1.3.0 + 5.2, however, when I updated to 1.4.1 all tests failed.

Versions (please complete the following information):

  • Python version: 3.12
  • Django version: 5.2
  • Django-Ninja version: 1.4.1
  • Pydantic version: 2.11.3

Test case:

class TestTradeRouterWithData(TestCase):

    def setUp(self):
        # self.api = NinjaAPI()
        # self.api.add_router(router=trade_router, prefix=0)
        self.client = TestAsyncClient(trade_router)

        baker.make(
            "core.Trade",
            _quantity=10,
            _fill_optional=True,
            data={"trader_name": "Nancy Pelosi", "issuer_name": "Apple"},
        )
        baker.make(
            "core.Trade",
            _quantity=50,
            _fill_optional=True,
            traded_date=make_aware(
                datetime(2023, 1, 12, 0, 0, 0, 0), DEFAULT_TIMEZONE_INFO
            ),
            data={"trader_name": "trader-2", "issuer_name": "Google 2"},
        )
        baker.make(
            "core.Trade",
            _quantity=50,
            _fill_optional=True,
            data={"trader_name": "trader 3", "issuer_name": "Google"},
        )

        self.assertEqual(Trade.objects.all().count(), 110)
        super().setUp()

    def tearDown(self):
        del self.client
        Trade.objects.all().delete()
        super().tearDown()

    async def test_fetch_trade(self):
        response: NinjaResponse = await self.client.get("")
        self.assertEqual(response.status_code, 200)

It was fine on 1.3.0 but failed on 1.4.1 and 1.4.0 with TypeError: 'list' object is not callable

Is it a bug or did I not use the right way to write my tests?

Any ideas? thanks. :)

@tim-hub
Copy link
Contributor Author

tim-hub commented Apr 9, 2025

I am trying to verify whether it is related to the change on ninja/testing/client.py

I tried to revert ninja/testing/client.py only, it does not help, so I think it is not related to the change on this ninja/testing/client.py.

@vitalik
Copy link
Owner

vitalik commented Apr 9, 2025

@tim-hub could you show full stack trace ?

@tim-hub
Copy link
Contributor Author

tim-hub commented Apr 9, 2025

@tim-hub could you show full stack trace ?

Thanks @vitalik

Error
Traceback (most recent call last):
  File "~/Library/Caches/pypoetry/virtualenvs/tradeinsight.info-312/lib/python3.12/site-packages/asgiref/sync.py", line 254, in __call__
    return call_result.result()
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "~/Library/Caches/pypoetry/virtualenvs/tradeinsight.info-312/lib/python3.12/site-packages/asgiref/sync.py", line 331, in main_wrap
    result = await self.awaitable(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/Development/ti/core/tests/api/test_trade_router.py", line 258, in test_fetch_trade
    response: NinjaResponse = await self.client.get("")
                              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/Development/ti/core/tests/api/test_trade_router.py", line 190, in _call
    return NinjaResponse(await func(request, **kwargs))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/Library/Caches/pypoetry/virtualenvs/tradeinsight.info-312/lib/python3.12/site-packages/ninja/operation.py", line 493, in _async_view
    return await cast(AsyncOperation, operation).run(request, *a, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/Library/Caches/pypoetry/virtualenvs/tradeinsight.info-312/lib/python3.12/site-packages/ninja/operation.py", line 347, in run
    error = await self._run_checks(request)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/Library/Caches/pypoetry/virtualenvs/tradeinsight.info-312/lib/python3.12/site-packages/ninja/operation.py", line 364, in _run_checks
    error = await self._run_authentication(request)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/Library/Caches/pypoetry/virtualenvs/tradeinsight.info-312/lib/python3.12/site-packages/ninja/operation.py", line 394, in _run_authentication
    return self.api.on_exception(request, exc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/Library/Caches/pypoetry/virtualenvs/tradeinsight.info-312/lib/python3.12/site-packages/ninja/main.py", line 520, in on_exception
    return handler(request, exc)
           ^^^^^^^^^^^^^^^^^^^^^
  File "~/Library/Caches/pypoetry/virtualenvs/tradeinsight.info-312/lib/python3.12/site-packages/ninja/errors.py", line 129, in _default_exception
    raise exc  # let django deal with it
    ^^^^^^^^^
  File "~/Library/Caches/pypoetry/virtualenvs/tradeinsight.info-312/lib/python3.12/site-packages/ninja/operation.py", line 392, in _run_authentication
    result = callback(request)
             ^^^^^^^^^^^^^^^^^
TypeError: 'list' object is not callable

I think the error is raised from operation.py

@tim-hub
Copy link
Contributor Author

tim-hub commented May 27, 2025

Any ideas for this issue, @vitalik

If there is no straight forward causes, I will just give up and stay on an old version for now.

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

2 participants