- Mailing Lists
- Contributors
- Re: Warning about creating a product and reusing its variable
Archives
- By thread 1472
-
By date
- August 2019 59
- September 2019 118
- October 2019 165
- November 2019 97
- December 2019 35
- January 2020 58
- February 2020 204
- March 2020 121
- April 2020 172
- May 2020 50
- June 2020 158
- July 2020 85
- August 2020 94
- September 2020 193
- October 2020 277
- November 2020 100
- December 2020 159
- January 2021 38
- February 2021 87
- March 2021 146
- April 2021 73
- May 2021 90
- June 2021 86
- July 2021 123
- August 2021 50
- September 2021 68
- October 2021 66
- November 2021 74
- December 2021 75
- January 2022 98
- February 2022 77
- March 2022 68
- April 2022 31
- May 2022 59
- June 2022 87
- July 2022 141
- August 2022 38
- September 2022 73
- October 2022 152
- November 2022 39
- December 2022 50
- January 2023 93
- February 2023 49
- March 2023 106
- April 2023 47
- May 2023 69
- June 2023 92
- July 2023 64
- August 2023 103
- September 2023 91
- October 2023 101
- November 2023 94
- December 2023 46
- January 2024 75
- February 2024 79
- March 2024 104
- April 2024 63
- May 2024 40
- June 2024 160
- July 2024 80
- August 2024 70
- September 2024 62
- October 2024 121
- November 2024 117
- December 2024 89
- January 2025 59
- February 2025 104
- March 2025 96
- April 2025 107
- May 2025 52
- June 2025 72
- July 2025 60
- August 2025 81
- September 2025 124
- October 2025 63
- November 2025 57
- December 2025 33
- January 2026 63
- February 2026 48
Contributors
contributors@odoo-community.org
Re: Warning about creating a product and reusing its variable
Sent: Saturday, 7 February 2026 2:37 AM
To: Contributors <contributors@odoo-community.org>
Subject: Warning about creating a product and reusing its variable
item_a = self.env["product.product"].browse(item_a.id)
item_b = item_a.copy({"name": "ItemB"})
Yann PAPOUIN, Ingénieur R&D | DEC
_______________________________________________
Mailing-List:
https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe:
https://odoo-community.org/groups?unsubscribe
by "Richard deMeester" <richard.demeester@willdooit.com> - 09:36 - 9 Feb 2026
Reference
-
Warning about creating a product and reusing its variable
Hi everyone,A small tip to avoid an headache :If you create a new productitem_a = self.env["product.product"].create({"name": "ItemA"})And then copy ititem_b = item_a.copy({"name": "ItemB"})You will have the surprise to see that "item_b" is en empty recordset.Why ? Simply because a context key is set by odoo (create_product_product=False) when creating a `product.product`So to avoid this issue, simply re-browse your newly created record to have a clean context:item_a = self.env["product.product"].create({"name": "ItemA"})
item_a = self.env["product.product"].browse(item_a.id)
item_b = item_a.copy({"name": "ItemB"})It is the second time in a week that I have an issue with context keys set inside a `create that stays in the context of the variable.I don't know if it should be considered a bug or not but I believe that if a context key is set from create/copy/etc. to fix some recursion issue, the context should be cleaned after super() before returning the final value--
Yann PAPOUIN, Ingénieur R&D | DEC
by Yann Papouin - 04:35 - 6 Feb 2026-
Re: Warning about creating a product and reusing its variable
I finally made a PR about this issue but without being sure that the fix is the way to go.--
Yann PAPOUIN, Ingénieur R&D | DECLe lun. 9 févr. 2026 à 09:37, Richard deMeester <notifications@odoo-community.org> a écrit :Ooh, thanks for that warning.
I would have said bug for the resulting recordset to have context values left over from its own needs...
Good luck getting that sorted, though, without proposing the fix yourself....
Cheers
Kind regards,Richard deMeesterDevelopment QAWilldooIT is a member of the PNORS Technology Group.
This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to which they are addressed. If you are not the intended recipient, you may not disclose or use the information in this email in any way. If you have received this email in error please notify the sender. Although reasonable precautions have been taken to ensure no viruses are present in this email, no responsibility is accepted by PNORS Technology Group Pty Ltd or its related entities for any loss or damage arising from the use of this email or attachments. Any views expressed in this email or file attachments are those of the individual sender only, unless expressly stated to be those of PNORS Technology Group Pty Ltd or any of its related entities.
From: Yann Papouin <notifications@odoo-community.org>
Sent: Saturday, 7 February 2026 2:37 AM
To: Contributors <contributors@odoo-community.org>
Subject: Warning about creating a product and reusing its variableHi everyone,
A small tip to avoid an headache :
If you create a new productitem_a = self.env["product.product"].create({"name": "ItemA"})And then copy ititem_b = item_a.copy({"name": "ItemB"})
You will have the surprise to see that "item_b" is en empty recordset.
Why ? Simply because a context key is set by odoo (create_product_product=False) when creating a `product.product`So to avoid this issue, simply re-browse your newly created record to have a clean context:item_a = self.env["product.product"].create({"name": "ItemA"})
item_a = self.env["product.product"].browse(item_a.id)
item_b = item_a.copy({"name": "ItemB"})It is the second time in a week that I have an issue with context keys set inside a `create that stays in the context of the variable.
I don't know if it should be considered a bug or not but I believe that if a context key is set from create/copy/etc. to fix some recursion issue, the context should be cleaned after super() before returning the final value
--
Yann PAPOUIN, Ingénieur R&D | DEC
_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe
_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe
by Yann Papouin - 12:06 - 9 Feb 2026 -
Re: Warning about creating a product and reusing its variable
Ooh, thanks for that warning.
I would have said bug for the resulting recordset to have context values left over from its own needs...
Good luck getting that sorted, though, without proposing the fix yourself....
Cheers
Kind regards,Richard deMeesterDevelopment QAWilldooIT is a member of the PNORS Technology Group.
This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to which they are addressed. If you are not the intended recipient, you may not disclose or use the information in this email in any way. If you have received this email in error please notify the sender. Although reasonable precautions have been taken to ensure no viruses are present in this email, no responsibility is accepted by PNORS Technology Group Pty Ltd or its related entities for any loss or damage arising from the use of this email or attachments. Any views expressed in this email or file attachments are those of the individual sender only, unless expressly stated to be those of PNORS Technology Group Pty Ltd or any of its related entities.
From: Yann Papouin <notifications@odoo-community.org>
Sent: Saturday, 7 February 2026 2:37 AM
To: Contributors <contributors@odoo-community.org>
Subject: Warning about creating a product and reusing its variableHi everyone,
A small tip to avoid an headache :
If you create a new productitem_a = self.env["product.product"].create({"name": "ItemA"})And then copy ititem_b = item_a.copy({"name": "ItemB"})
You will have the surprise to see that "item_b" is en empty recordset.
Why ? Simply because a context key is set by odoo (create_product_product=False) when creating a `product.product`So to avoid this issue, simply re-browse your newly created record to have a clean context:item_a = self.env["product.product"].create({"name": "ItemA"})
item_a = self.env["product.product"].browse(item_a.id)
item_b = item_a.copy({"name": "ItemB"})It is the second time in a week that I have an issue with context keys set inside a `create that stays in the context of the variable.
I don't know if it should be considered a bug or not but I believe that if a context key is set from create/copy/etc. to fix some recursion issue, the context should be cleaned after super() before returning the final value
--
Yann PAPOUIN, Ingénieur R&D | DEC
_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe
by "Richard deMeester" <richard.demeester@willdooit.com> - 09:36 - 9 Feb 2026
-