Skip to content

Remove requests, use httpx for sync and async HTTP requests#876

Open
Marc-Andrieu wants to merge 3 commits intomainfrom
rm/req
Open

Remove requests, use httpx for sync and async HTTP requests#876
Marc-Andrieu wants to merge 3 commits intomainfrom
rm/req

Conversation

@Marc-Andrieu
Copy link
Copy Markdown
Member

Description

Summary

Split #845 into a 3rd PR with only the removal of requests and its major consequence: send logs asynchronously.

Changes Made

  • replace all requests use with httpx, or remove it
    • consequence: the asynchronicity of sending logs propagates, and is escaped using FastAPI's BackgroundTasks

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 🔨 Refactor (non-breaking change that neither fixes a bug nor adds a feature)
  • 🔧 Infra CI/CD (changes to configs of workflows)
  • 💥 BREAKING CHANGE (fix or feature that require a new minimal version of the front-end)

Impact & Scope

  • Core functionality changes
  • Single module changes
  • Multiple modules changes
  • Database migrations required
  • Other

Testing

  • Added/modified tests that pass the CI
  • Tested in a pre-prod
  • Tested this locally

Documentation

  • Updated docs accordingly (docs.myecl.fr) :
  • Code includes docstrings
  • No documentation needed

@Marc-Andrieu Marc-Andrieu self-assigned this Oct 14, 2025
@Marc-Andrieu Marc-Andrieu added dependencies Pull requests that update a dependency file core logging ready for review This PR is ready to be reviewed labels Oct 14, 2025
@Marc-Andrieu Marc-Andrieu changed the title Rm/req Remove requests and support async logging Oct 14, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.43%. Comparing base (91177eb) to head (5e16854).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #876   +/-   ##
=======================================
  Coverage   84.43%   84.43%           
=======================================
  Files         206      206           
  Lines       14918    14918           
=======================================
  Hits        12596    12596           
  Misses       2322     2322           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


try:
self.matrix.send_message(self.room_id, msg)
self.background_tasks.add_task(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loggers are encapsulated in a QueueHandlers which send logs in a dedicated thread. I'm honstly unsure about the consequences of using FastAPI BackgroundTask here.
I believe:

  • it should be unneeded as logs are already sent in their own thread
  • depending on BackgroundTask implementation, it could pull back the log emission in the main thread, which would be counterproductive
  • the execution of the task would be planned by FastAPI, at an unknown instant. We have no guarantee that a task added outside endpoint executions would be instantly scheduled.

I these fears are unfounded, I think it would be a good thing to add comments in the code explaining the benefits of using a BackgroundTask here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right... Even the native logging HTTPHandler (https://docs.python.org/3/library/logging.handlers.html#httphandler) seems synchronous...

After all I don't care much about the "sync vs async" debate per se, I just want:

  • to remove requests and type_requests from our dependencies
  • not to alter the current performance

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: this PR is about to become a LOT easier!
The very 1st sentence of https://www.python-httpx.org/ states that httpx "provides sync and async APIs"

@Marc-Andrieu Marc-Andrieu changed the title Remove requests and support async logging Remove requests, use httpx for sync and async HTTP requests Mar 28, 2026
@Marc-Andrieu Marc-Andrieu changed the title Remove requests, use httpx for sync and async HTTP requests Remove requests, use httpx for sync and async HTTP requests Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core dependencies Pull requests that update a dependency file logging ready for review This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants