Skip to content

[16.0][FIX] product_variant_default_code: avoid unnecessary writes#429

Merged
OCA-git-bot merged 1 commit intoOCA:16.0from
BITVAX:16.0-fix-default-code-serialization
May 8, 2026
Merged

[16.0][FIX] product_variant_default_code: avoid unnecessary writes#429
OCA-git-bot merged 1 commit intoOCA:16.0from
BITVAX:16.0-fix-default-code-serialization

Conversation

@IJOL
Copy link
Copy Markdown

@IJOL IJOL commented Nov 26, 2025

Description

Optimizes the default_code computation in product variants:

  1. Avoid unnecessary writes: Only writes to default_code when the value actually changes. in db with many products makes upgrades faster

  2. Early return without reference_mask: Returns None early in _generate_default_code() when no reference_mask is defined, avoiding unnecessary processing, that was causing error during upgrades when database already contain many products and no automask setting is on

Testing

  • Tested in production environment with concurrent product updates
  • No more serialization errors when multiple users edit products simultaneously

Checklist

  • Fixes a bug
  • Code follows OCA guidelines
  • Tests pass

@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hi @Kev-Roche,
some modules you are maintaining are being modified, check this out!

Comment on lines +230 to +238
return None
else:
if not self.product_tmpl_id.reference_mask:
return None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplier:

Suggested change
return None
def _generate_default_code(self):
value_codes = self.product_tmpl_id.attribute_line_ids.value_ids.mapped("code")
if (not self.code_prefix and self.product_tmpl_id.is_automask()) or not all(
value_codes or not self.product_tmpl_id.reference_mask
):
return None
else:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks

@IJOL IJOL force-pushed the 16.0-fix-default-code-serialization branch from 64599e2 to dd6a477 Compare December 3, 2025 08:46
Optimize default_code computation to avoid:
- Unnecessary write operations when the value hasn't changed
- PostgreSQL serialization errors in concurrent transactions
- Processing when no reference_mask is defined (early return)
@IJOL IJOL force-pushed the 16.0-fix-default-code-serialization branch from dd6a477 to a3beb7d Compare December 3, 2025 08:48
@IJOL IJOL requested a review from Kev-Roche December 3, 2025 08:50
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 5, 2026

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions Bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Apr 5, 2026
@pedrobaeza pedrobaeza added this to the 16.0 milestone May 8, 2026
Copy link
Copy Markdown
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fw-port it to upper versions:

/ocabot merge patch

@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 16.0-ocabot-merge-pr-429-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot
Copy link
Copy Markdown
Contributor

@pedrobaeza your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-429-by-pedrobaeza-bump-patch.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@pedrobaeza
Copy link
Copy Markdown
Member

Retrying after #442

/ocabot merge patch

@OCA-git-bot
Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-429-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 1ddeb2d into OCA:16.0 May 8, 2026
7 checks passed
@OCA-git-bot
Copy link
Copy Markdown
Contributor

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

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

Labels

merged 🎉 stale PR/Issue without recent activity, it'll be soon closed automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants