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

[16.0][FIX] fastapi: Transactions handling refactoring #422

Merged
merged 5 commits into from
Jun 6, 2024

Commits on Jun 6, 2024

  1. [FIX] fastapi: Enable auto retry of calls

    This change fix an issue that prevented the system to retry a call to the
    application in case of a DB concurrency error if this error is defined as
    retryable.
    
    By default, any call to the application is retried in case of a DB concurrency
    if retryable. The 'retry' mechanism is implemented at the early stage of the processing
    of a request in case of specific postgreSQL errors. When a call is made to
    a fastapi application, the specific handler for the request is placed further
    down the stack. Before this change, any error that occurred in the specific
    fastapi handler was catch by the Fastapi processing stack and never bubbled up
    to the early stage of the processing where the 'retry' mechanism is implemented.
    
    This change fix this issue by putting in place a way to make some specific
    exceptions bubble up the fastapi processing stack through the event loop required
    to transform WSGI to ASGI.
    lmignon committed Jun 6, 2024
    Configuration menu
    Copy the full SHA
    a6b48ad View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    37027d5 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    13ae2e6 View commit details
    Browse the repository at this point in the history
  4. [FIX] fastapi: Readme

    lmignon committed Jun 6, 2024
    Configuration menu
    Copy the full SHA
    8f2cf26 View commit details
    Browse the repository at this point in the history
  5. [FIX] fastapi: Transactions handling refactoring

    This change is a complete rewrite of the way the transactions are managed when
    integrating a fastapi application into Odoo.
    
    In the previous implementation, specifics error handlers were put in place to
    catch exception occurring in the handling of requests made to a fastapi application
    and to rollback the transaction in case of error. This was done by registering
    specifics error handlers methods to the fastapi application using the 'add_exception_handler'
    method of the fastapi application. In this implementation, the transaction was
    rolled back in the error handler method.
    
    This approach was not working as expected for several reasons:
    
    - The handling of the error at the fastapi level prevented the retry mechanism
      to be triggered in case of a DB concurrency error. This is because the error
      was catch at the fastapi level and never bubbled up to the early stage of the
      processing of the request where the retry mechanism is implemented.
    - The cleanup of the environment and the registry was not properly done in case
      of error. In the **'odoo.service.model.retrying'** method, you can see that
      the cleanup process is different in case of error raised by the database
      and in case of error raised by the application.
    
    This change fix these issues by ensuring that errors are no more catch at the
    fastapi level and bubble up the fastapi processing stack through the event loop
    required to transform WSGI to ASGI. As result the transactional nature of the
    requests to the fastapi applications is now properly managed by the Odoo framework.
    lmignon committed Jun 6, 2024
    Configuration menu
    Copy the full SHA
    05c663e View commit details
    Browse the repository at this point in the history