Repository navigation
[19.0][FIX] fordward port of missing commits - #3729
sergio-teruel wants to merge 8 commits into
Conversation
This aims to solve issues when modules not depending on whatever implementation of base_exception, override the same function that triggers the detection of exceptions. Before this commit, any changes done in such overrides could end up being committed to the database if the MRO did execute such function before the function implementing base_exception that avoids to call super in case an exception is detected. (eg sale.order. action_confirm in sale_exception) With this commit, in case there is any newly detected exception, or a record with exception that is not ignored, or a blocking exception linked to a record, exception changes will be committed in DB while a specific Exception type will be raised to rollback any changes done in the ongoing transaction. Such an exception will be handled in the UI to refresh the exception_ids field so that the user knows why the action was not completed.
With the previous change raising an exception to rollback a transaction, the function `_popup_exceptions` could not be called anymore while the error was raised. Instead, we provide now a hook `_must_popup_exception` that can be redefined by model and will be called when `action_popup_exception` is called by the webclient, to smoothly refresh the page and display the popup exception wizard.
Simplify the JS layer by leveraging client actions. Return a custom client action whenever the BaseExceptionError is catched on RPC call and handle everything through the call to action_popup_exceptions: - In case exception should not pop up, return a soft reload client action instead of handling the refresh manually in JS - In case exception should pop up, return the wizard action, but do a soft reload first to display the exception_ids block before execution the wizard opening action.
Make test decorator available for import in other modules Avoid using new env for unrelated tests
detect_exceptions() stores the exceptions in a separate transaction (a new cursor/connection) so that they are kept when the ongoing transaction is rolled back. When the registry is not ready yet (module installation or update), the ongoing transaction holds exclusive locks on the tables it has just modified (ALTER TABLE ...). The call to _must_raise_exception_after_detection() made inside that new transaction then reads the model records, and the query waits for those locks forever: the only thread able to release them is the one waiting for them. This happens as soon as demo data confirming a sale order is loaded during a database initialisation with sale_exception installed (e.g. the sale_stock demo data), making the whole database initialisation hang. Use the current cursor in that case, as already done when running tests.
…transaction detect_exceptions() opens a second, genuinely independent DB connection (self.env.registry.cursor()) to write exception flags so they survive a rollback of the ongoing transaction. It then re-derived main_records through that same second connection (self.with_env(new_env)), which crashes with MissingError whenever _get_main_records() has to read a field on records created earlier in the SAME ongoing transaction and not yet committed (e.g. sale.order.line._get_main_records() reading order_id right after the line was created by write()). Typical trigger: adding a product to an already confirmed sale order. sale_exception.write() re-runs detect_exceptions() on order_line whenever order_line changes on a confirmed order; the new line only exists in the ongoing transaction, so the second connection can't see it yet. Resolve main_records once through the original (main) cursor, which does see the just-created records, and only rebind that already-resolved recordset to the new environment for the exception_ids check.
|
Hi @hparfr, @sebastienbeau, |
Odoo 19.0 dropped 'decorator' from its core requirements.txt (present in18.0). base_exception's tests use it directly (via the decorator package, not through odoo_test_helper as in 18.0), so CI fails with ModuleNotFoundError: No module named 'decorator' when running the forward-ported test suite.
Odoo 19.0 renamed Registry.enter_test_mode(cr)/leave_test_mode() to TransactionCase.registry_enter_test_mode()/registry_leave_test_mode(), with automatic cleanup registration. test_rollback_main_transaction (forward-ported from 18.0 in an earlier commit) still used the old API, failing with AttributeError: 'Registry' object has no attribute 'enter_test_mode'.
|
|
||
| @api.model | ||
| def _get_popup_action(self): | ||
| return self.env.ref("base_exception.action_exception_rule_confirm") |
There was a problem hiding this comment.
Please adapt this code. You should use self.env["ir.actions.actions"]._for_xml_id().
| if field in record._get_readable_fields() | ||
| } | ||
| action.update( | ||
| # TODO: When migrating, use _for_xml_id instead of this |
There was a problem hiding this comment.
Once you adapt the code as commented here: https://github.com/OCA/server-tools/pull/3729/changes#r4036710316 please remove the TODO.
|
Could you include this? #3734 |
|
FYI, #3741 ("[18.0][FIX] base_exception: allow detecting exceptions without rollback") was merged on 18.0 on 2026-10-30 as a follow-up of #3590 (c481946 here). It fixes a hang: |
|
Thanks for porting these commits. One note on Without it, when the user confirms through the exception dialog (for example ticking Ignore Exceptions), the record is updated in the database but the view behind the dialog still shows the old state, with the warning banner and the Confirm button. You have to reload by hand, and until you do, the same record can be confirmed again. The wizard returns The 20.0 migration (#3800) already carries the fix plus a guard against a double reload: // A button of the dialog closes it twice: through the act_window_close
// action it returns, and again when the soft_reload closes the dialogs,
// as the dialog is still open while onClose runs. Reload only once.
let reloaded = false;
await env.services.action.doAction(popupAction, {
onClose: () => {
if (reloaded) return;
reloaded = true;
return env.services.action.doAction({
type: "ir.actions.client",
tag: "soft_reload",
});
},
});Could you include that here? It is a few lines on a file this PR is creating anyway, and it avoids 19.0 shipping with a bug that is already fixed in both 18.0 and 20.0. |
|
One more thing, found while forward porting the @decorator
def swallow_base_exception_error(func, self):
def wrapper(*args, **kwargs): # returned, never called
try:
return func(*args, **kwargs)
except BaseExceptionError:
return None
return wrapperWith It shows up in the query counts. Same suite, same database, only the decorator changed: The tests still pass once it is fixed ( @decorator
def swallow_base_exception_error(func, self):
try:
return func(self)
except BaseExceptionError:
return NoneWorth fixing in 18.0 too. |
|
Hi @sergio-teruel, thanks for starting this forward port. Two more |
Missing commits from 18.0: