Skip to content

[19.0][FIX] edi_core_oca: use savepoint to prevent state corruption on errors - #316

Merged
OCA-git-bot merged 1 commit into
OCA:19.0from
qoqa:19.0-fix-error-handling-state-corruption
Jul 3, 2026
Merged

[19.0][FIX] edi_core_oca: use savepoint to prevent state corruption on errors#316
OCA-git-bot merged 1 commit into
OCA:19.0from
qoqa:19.0-fix-error-handling-state-corruption

Conversation

@guewen

@guewen guewen commented Jul 3, 2026

Copy link
Copy Markdown
Member

Forward #284

Some errors such as

  ValueError,
  FileNotFoundError,
  exceptions.UserError,
  exceptions.ValidationError,

are caught, never re-raised, and the transaction is finally committed.

Which means a UserError/ValidationError gets committed, leading to
corruption of the processed data.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @etobella, @simahawk,
some modules you are maintaining are being modified, check this out!

@guewen guewen changed the title [FIX] edi_core_oca: use savepoint to prevent state corruption on errors [19.0][FIX] edi_core_oca: use savepoint to prevent state corruption on errors Jul 3, 2026
@simahawk

simahawk commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 19.0-ocabot-merge-pr-316-by-simahawk-bump-patch, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 1d528c4 into OCA:19.0 Jul 3, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 4bce3cf. Thanks a lot for contributing to OCA. ❤️

@HviorForgeFlow

Copy link
Copy Markdown
Member

@simahawk @etobella @guewen this change brokes edi_queue_oca module, because doubling the savepoint (queue one and now edi_core_oca one) makes lose environment context :(

@guewen

guewen commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

this change brokes edi_queue_oca module, because doubling the savepoint (queue one and now edi_core_oca one) makes lose environment context :(

@HviorForgeFlow do you have more details about this? Are you sure it is related? As far as I know, successful savepoints do not alter the environment or the context. BTW we are using this patch in production (in 18.0 though) since May 21th alongside edi_queue_oca.

@HviorForgeFlow

HviorForgeFlow commented Jul 7, 2026

Copy link
Copy Markdown
Member

@guewen I need investigate further but take a look on the error on the process:

Expected singleton: res.users()
Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/orm/models.py", line 5939, in ensure_one
    _id, = self._ids
    ^^^^
ValueError: not enough values to unpack (expected 1, got 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/odoo/auto/addons/edi_core_oca/models/edi_backend.py", line 480, in exchange_process
    with self.env.cr.savepoint():
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 116, in __exit__
    self.close(rollback=exc_type is not None)
  File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 120, in close
    self._close(rollback)
  File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 146, in _close
    self._cr.flush()
  File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 182, in flush
    self.transaction.flush()
  File "/opt/odoo/custom/src/odoo/odoo/orm/environments.py", line 592, in flush
    self.default_env.flush_all()
  File "/opt/odoo/custom/src/odoo/odoo/orm/environments.py", line 383, in flush_all
    self._recompute_all()
  File "/opt/odoo/custom/src/odoo/odoo/orm/environments.py", line 376, in _recompute_all
    self[field.model_name]._recompute_field(field)
  File "/opt/odoo/custom/src/odoo/odoo/orm/models.py", line 6960, in _recompute_field
    field.recompute(records)
  File "/opt/odoo/custom/src/odoo/odoo/orm/fields.py", line 1891, in recompute
    apply_except_missing(self.compute_value, recs)
  File "/opt/odoo/custom/src/odoo/odoo/orm/fields.py", line 1861, in apply_except_missing
    func(records)
  File "/opt/odoo/custom/src/odoo/odoo/orm/fields.py", line 1915, in compute_value
    records._compute_field_value(self)
  File "/opt/odoo/auto/addons/mail/models/mail_thread.py", line 484, in _compute_field_value
    return super()._compute_field_value(field)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/custom/src/odoo/odoo/orm/models.py", line 4954, in _compute_field_value
    determine(field.compute, self)
  File "/opt/odoo/custom/src/odoo/odoo/orm/fields.py", line 81, in determine
    return needle(*args)
           ^^^^^^^^^^^^^
  File "/opt/odoo/auto/addons/account_accountant/models/account_move.py", line 76, in _compute_signing_user
    is_backend_user = self.env.user.has_group('base.group_user')
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/res_users.py", line 1074, in has_group
    self.ensure_one()
  File "/opt/odoo/custom/src/odoo/odoo/orm/models.py", line 5942, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: res.users()

@guewen

guewen commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

That's weird indeed. The savepoint does a flush, perhaps at this point in the code execution any flush would crash like this, so the fact that it happens on this savepoint might be only a symptom?

@HviorForgeFlow

Copy link
Copy Markdown
Member

By default queue job do a savepoint, but when doing the second by edi_core_oca, it crashes...need further investigation yes...maybe in v18 it is not happening, or just the code don't check the user or other context which don't crash anything.

@guewen

guewen commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

@HviorForgeFlow it may be related to this OCA/queue#922 actually?

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

@guewen I have looked into it, and yes, it seems OCA/queue#923 fixes the issue @HviorForgeFlow faced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants