-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[18.0][FIX] base_exception: Rollback transaction if we detect exceptions #3590
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
grindtildeath
wants to merge
14
commits into
OCA:18.0
Choose a base branch
from
camptocamp:18.0-fix-base_exception_rollback_transaction_fix_ui
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
61eed8a
[FIX] base_exception: Rollback transaction if we detect exceptions
grindtildeath 9a1c94c
Fix tests
grindtildeath 08266fe
[REF] base_exception: Handle the exception popup at client level
grindtildeath e1b81f8
[REF] base_exception: Use a client action to reload smoothly
grindtildeath 1a2e3c6
fixup! [REF] base_exception: Use a client action to reload smoothly
grindtildeath 9857533
fixup! fixup! [REF] base_exception: Use a client action to reload smo…
grindtildeath c008459
[TEST] base_exception: Test exception rollbacking
grindtildeath e9c8a9d
fixup! fixup! fixup! [REF] base_exception: Use a client action to rel…
grindtildeath c548c60
fixup! fixup! fixup! fixup! [REF] base_exception: Use a client action…
grindtildeath 190597f
fixup! [FIX] base_exception: Rollback transaction if we detect except…
grindtildeath 20a2885
fixup! fixup! fixup! fixup! fixup! [REF] base_exception: Use a client…
grindtildeath c309ca0
Make test decorator available for import in other modules
grindtildeath f1b8586
fixup! fixup! fixup! fixup! fixup! fixup! [REF] base_exception: Use a…
grindtildeath 78412ea
Avoid using new env for unrelated tests
grindtildeath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright 2025 Camptocamp SA | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
|
||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class BaseExceptionError(UserError): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import {registry} from "@web/core/registry"; | ||
|
|
||
| /* eslint-disable no-unused-vars */ | ||
| async function popUpException(env, _action) { | ||
| /* eslint-enable no-unused-vars */ | ||
| const controller = env.services.action.currentController; | ||
| const orm = env.services.orm; | ||
| const resId = controller.currentState?.resId; | ||
| const resModel = controller.props.resModel; | ||
| if (!resModel || !resId) return; | ||
| const popupAction = await orm.call(resModel, "action_popup_exceptions", [[resId]]); | ||
| if (!popupAction) return; | ||
| // Do a soft reload before displaying the popup to display the exception | ||
| // on the Form view | ||
| await env.services.action.restore(controller.jsId); | ||
| await env.services.action.doAction(popupAction); | ||
| } | ||
|
|
||
| function baseExceptionErrorHandler(env, uncaughtError, originalError) { | ||
| const controller = env.services.action.currentController; | ||
| if ( | ||
| originalError.exceptionName === | ||
| "odoo.addons.base_exception.exceptions.BaseExceptionError" | ||
| ) { | ||
| const excData = JSON.parse(originalError.data.message); | ||
| if (excData.target_model === controller.props.resModel) { | ||
| env.services.action.doAction({ | ||
| type: "ir.actions.client", | ||
| tag: "popup_exception", | ||
| }); | ||
| } else { | ||
| env.services.action.doAction({ | ||
| type: "ir.actions.client", | ||
| tag: "soft_reload", | ||
| }); | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| registry.category("actions").add("popup_exception", popUpException); | ||
| registry | ||
| .category("error_handlers") | ||
| .add("base_exception_error", baseExceptionErrorHandler, {sequence: 0}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Copyright 2026 Camptocamp SA | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
|
||
| try: | ||
| from decorator import decoratorx as decorator | ||
| except ImportError: | ||
| from decorator import decorator | ||
|
|
||
| from contextlib import contextmanager | ||
| from unittest.mock import patch | ||
|
|
||
| from ..exceptions import BaseExceptionError | ||
|
|
||
|
|
||
| @decorator | ||
| def swallow_base_exception_error(func, self): | ||
| def wrapper(*args, **kwargs): | ||
| try: | ||
| return func(*args, **kwargs) | ||
| except BaseExceptionError: | ||
| return None | ||
|
|
||
| return wrapper | ||
|
|
||
|
|
||
| @contextmanager | ||
| def mock_base_exception_method_env(self, env=None): | ||
| if env is None: | ||
| env = self.env | ||
| with patch( | ||
| "odoo.addons.base_exception.models.base_exception_method.Environment" | ||
| ) as mocked_env: | ||
| mocked_env.return_value = env | ||
| yield | ||
|
|
||
|
|
||
| @decorator | ||
| def patch_base_exception_method_env(func, self): | ||
| with mock_base_exception_method_env(self): | ||
| return func(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.