[18.0] base_exception: swallow_base_exception_error never runs the decorated test

Open Beginner friendly
#3,784 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@SparkDrago05 is already working on this.

Since Oct 17, 2026.

  • #3793 by @SparkDrago05 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
testing

Research direction

Read base_exception/tests/common.py and inspect how the decorator package invokes the decorated test. The issue provides a reproduction showing the test body is skipped and a possible fix that calls the function inside the decorator. Update the helper and run its affected tests; done means the test body executes and expected BaseExceptionError handling still works.

Written by the indexing model from the issue text.

Description

Problem

swallow_base_exception_error in base_exception/tests/common.py (18.0) never runs the test it decorates:

@decorator
def swallow_base_exception_error(func, self):
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except BaseExceptionError:
            return None

    return wrapper

With decorator, the caller's return value is the result of the decorated call. This caller returns wrapper without calling it, so the test method returns a function object and its body is skipped. The test is then reported as passed.

Reproduction

With the decorator package shipped in the official odoo:18.0 image (5.1.1):

from decorator import decoratorx as decorator

@decorator
def swallow(func, self):
    def wrapper(*a, **k):
        try:
            return func(*a, **k)
        except ValueError:
            return None
    return wrapper

class T:
    @swallow
    def test(self):
        print("BODY RAN")
        raise AssertionError("fail inside")

print(T().test())
# <function swallow.<locals>.wrapper at 0x...>   ("BODY RAN" is never printed)

Impact

Tests decorated with it pass without running any of their assertions. For example, several tests in sale_exception (OCA/sale-workflow#4255) and purchase_exception / purchase_request_exception (OCA/purchase-workflow#3012) use it.

Possible fix

Call the function inside the caller:

@decorator
def swallow_base_exception_error(func, self):
    try:
        return func(self)
    except BaseExceptionError:
        return None

With that, the decorated tests start running again, so some may need adjusting. A test that stops at the first BaseExceptionError also skips its remaining assertions. Asserting the error explicitly where it is expected may be safer than swallowing it for the whole test.

I found this while adapting hr_expense_exception (OCA/hr-expense#388, fix in OCA/hr-expense#391). That PR checks the error explicitly instead of using this helper.

Dominant language
Python
Stars
960
Forks
1.7k
Avg merge
5d 23h
Merged PRs (30d)
15

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OCA/server-tools

All issues in OCA/server-tools

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.