Skip to content

[IMP] fastapi: httpx deprecated#629

Open
SirPyTech wants to merge 1 commit into
OCA:16.0from
PyTech-SRL:16.0-imp-fastapi-httpx2_warn
Open

[IMP] fastapi: httpx deprecated#629
SirPyTech wants to merge 1 commit into
OCA:16.0from
PyTech-SRL:16.0-imp-fastapi-httpx2_warn

Conversation

@SirPyTech

Copy link
Copy Markdown
Contributor

This change gets rid of the following warning that is logged in the latest test run:

StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated; install `httpx2` instead.
2026-07-06 09:17:28,300 432 WARNING odoo py.warnings: /opt/odoo-venv/lib/python3.10/site-packages/fastapi/testclient.py:1: StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated; install `httpx2` instead.
  File "/opt/odoo-venv/bin/coverage", line 6, in 
    sys.exit(main())
  File "/opt/odoo-venv/lib/python3.10/site-packages/coverage/cmdline.py", line 1164, in main
    status = CoverageScript().command_line(argv)
  File "/opt/odoo-venv/lib/python3.10/site-packages/coverage/cmdline.py", line 853, in command_line
    return self.do_run(options, args)
  File "/opt/odoo-venv/lib/python3.10/site-packages/coverage/cmdline.py", line 1043, in do_run
    runner.run()
  File "/opt/odoo-venv/lib/python3.10/site-packages/coverage/execfile.py", line 213, in run
    exec(code, main_mod.__dict__)
  File "/opt/odoo-venv/bin/odoo", line 8, in 
    odoo.cli.main()
  File "/opt/odoo/odoo/cli/command.py", line 66, in main
    o.run(args)
  File "/opt/odoo/odoo/cli/server.py", line 187, in run
    main(args)
  File "/opt/odoo/odoo/cli/server.py", line 180, in main
    rc = odoo.service.server.start(preload=preload, stop=stop)
  File "/opt/odoo/odoo/service/server.py", line 1433, in start
    rc = server.run(preload, stop)
  File "/opt/odoo/odoo/service/server.py", line 602, in run
    rc = preload_registries(preload)
  File "/opt/odoo/odoo/service/server.py", line 1333, in preload_registries
    registry = Registry.new(dbname, update_module=update_module)
  File "", line 2, in new
  File "/opt/odoo/odoo/tools/func.py", line 87, in locked
    return func(inst, *args, **kwargs)
  File "/opt/odoo/odoo/modules/registry.py", line 87, in new
    odoo.modules.load_modules(registry, force_demo, status, update_module)
  File "/opt/odoo/odoo/modules/loading.py", line 493, in load_modules
    processed_modules += load_marked_modules(cr, graph,
  File "/opt/odoo/odoo/modules/loading.py", line 374, in load_marked_modules
    loaded, processed = load_module_graph(
  File "/opt/odoo/odoo/modules/loading.py", line 284, in load_module_graph
    suite = loader.make_suite([module_name], 'at_install')
  File "/opt/odoo/odoo/tests/loader.py", line 76, in make_suite
    return OdooSuite(sorted(tests, key=lambda t: t.test_sequence))
  File "/opt/odoo/odoo/tests/loader.py", line 72, in 
    for m in get_test_modules(module_name)
  File "/opt/odoo/odoo/tests/loader.py", line 19, in get_test_modules
    results = _get_tests_modules(importlib.util.find_spec(f'odoo.addons.{module}'))
  File "/opt/odoo/odoo/tests/loader.py", line 30, in _get_tests_modules
    tests_mod = importlib.import_module(spec.name)
  File "/__w/rest-framework/rest-framework/fastapi/tests/__init__.py", line 2, in 
    from . import test_fastapi_demo
  File "/__w/rest-framework/rest-framework/fastapi/tests/test_fastapi_demo.py", line 16, in 
    from .common import FastAPITransactionCase
  File "/__w/rest-framework/rest-framework/fastapi/tests/common.py", line 20, in 
    from fastapi.testclient import TestClient
  File "/opt/odoo-venv/lib/python3.10/site-packages/fastapi/testclient.py", line 1, in 
    from starlette.testclient import TestClient as TestClient  # noqa

(from https://github.com/OCA/rest-framework/actions/runs/28780900500/job/85335980094#step:8:75)

StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated; install `httpx2` instead.
@oerp-odoo

Copy link
Copy Markdown

One note using httpx2.

It has this dependency (idna>=3.18):
https://github.com/pydantic/httpx2/blob/95aebc3e482ea952f044ed77f9782713039bc106/src/httpx2/pyproject.toml#L50

But standard odoo does (idna==3.6 ; python_version >= '3.12'): https://github.com/odoo/odoo/blob/65dbcabcd243abf24d6d3c3788d2caff66485790/requirements.txt#L31

So you might need to resolve this.

@SirPyTech

Copy link
Copy Markdown
Contributor Author

One note using httpx2.

It has this dependency (idna>=3.18): https://github.com/pydantic/httpx2/blob/95aebc3e482ea952f044ed77f9782713039bc106/src/httpx2/pyproject.toml#L50

But standard odoo does (idna==3.6 ; python_version >= '3.12'): https://github.com/odoo/odoo/blob/65dbcabcd243abf24d6d3c3788d2caff66485790/requirements.txt#L31

So you might need to resolve this.

Thanks for reporting this! I actually didn't know it.
Note that the Odoo requirement you linked is for 18.0 but this PR is for 16.0 so the requirement is actually

idna==2.10

(from https://github.com/odoo/odoo/blob/6aca71c9522b3be5b221847e8b005f233d3ea872/requirements.txt#L22)
that is even worse 😰

I don't know why Odoo is so strict about that requirement, but one thing I see is that in this repository's 18.0 we already have the requirement for httpx2:

Moreover this is a change only for the test environment (it changes test-requirements.txt) so maybe there are no big issues using it?
Let's see what the @OCA/rest-framework-maintainers think.

@oerp-odoo

Copy link
Copy Markdown

Yeah, I actually posted for Odoo 19 as I was setting up fastapi with that version and noticed issue with idna dependency. I assume odoo at some point tested that idna version and pinned to it as it was working for them. So they don't want to risk it and make it looser:). For testing environment I assume it should be fine as it probably just overwrites dependencies without trying to resolve like pip-tools or similar would do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants