Skip to content

Conversation

@IJOL
Copy link

@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
Contributor

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

Comment on lines 230 to 238
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
):
return None
else:
if not self.product_tmpl_id.reference_mask:
return None
Copy link
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants