From 05a00fa9d4f001cef6d31a5b8d20a847de4f455b Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Thu, 12 Jul 2018 17:41:05 +0200 Subject: [PATCH] [FIX] product: variant num w/o prefetch pollution When getting: - product_variant_count, - sales_count, of a product.product, we would pollute the records to be prefetched by all the variants when counting the number of variants. Thus if this happened before sales_count, we would possibly compute the sales_count for up to 1000 records when it could have been needed for just one. By using `.with_prefetch()`, a recordset will have its own records to be prefetched list and will not pollute the original one. opw-1865111 fixes #25649 closes #23112 (PR with similar fix) closes #25741 --- addons/product/models/product_template.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index f8a4ffea081..9056d40972b 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -250,7 +250,8 @@ class ProductTemplate(models.Model): @api.one @api.depends('product_variant_ids.product_tmpl_id') def _compute_product_variant_count(self): - self.product_variant_count = len(self.product_variant_ids) + # do not pollute variants to be prefetched when counting variants + self.product_variant_count = len(self.with_prefetch().product_variant_ids) @api.depends('product_variant_ids', 'product_variant_ids.default_code') def _compute_default_code(self):