Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions addons/product/migrations/13.0.1.2/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ def convert_image_attachments(env):
'product.product': "image_variant",
'product.template': "image",
}
attachment_model = env['ir.attachment']
for model, field in mapping.items():
Model = env[model]
attachments = env['ir.attachment'].search([
attachment_ids = attachment_model.search([
('res_model', '=', model),
('res_field', '=', field),
('res_id', '!=', False),
])
for attachment in attachments:
]).ids
# a MemoryError can happen if too many attachments are loaded in
# memory. therefore, we only load one record at the time and flush the
# cache at each iteration.
for attachment_id in attachment_ids:
Copy link
Contributor

@MiquelRForgeFlow MiquelRForgeFlow Nov 19, 2025

Choose a reason for hiding this comment

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

Suggested change
for attachment_id in attachment_ids:
for i, attachment_id in enumerate(attachment_ids, 1):

# load attachments one by one to avoid prefetching
attachment = attachment_model.browse(attachment_id)
try:
Model.browse(attachment.res_id).image_1920 = attachment.datas
except Exception as e:
Expand All @@ -32,6 +38,10 @@ def convert_image_attachments(env):
attachment.res_id,
repr(e),
)
# flush and clear cache to avoid to fill up memory and force the
Comment on lines 40 to +41
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
)
# flush and clear cache to avoid to fill up memory and force the
)
if i % 500 != 0:
continue
# flush and clear cache to avoid to fill up memory and force the

# computation of the computed fields (smaller size images)
Model.flush()
env.cache.invalidate()


@openupgrade.logging()
Expand Down
16 changes: 13 additions & 3 deletions addons/website_sale/migrations/13.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ def convert_image_attachments(env):
'product.image': "image",
'product.public.category': "image",
}
attachment_model = env['ir.attachment']
for model, field in mapping.items():
Model = env[model]
attachments = env['ir.attachment'].search([
attachment_ids = attachment_model.search([
('res_model', '=', model),
('res_field', '=', field),
('res_id', '!=', False),
])
for attachment in attachments:
]).ids
# a MemoryError can happen if too many attachments are loaded in
# memory. therefore, we only load one record at the time and flush the
# cache at each iteration.
for attachment_id in attachment_ids:
# load attachments one by one to avoid prefetching
attachment = attachment_model.browse(attachment_id)
try:
Model.browse(attachment.res_id).image_1920 = attachment.datas
except Exception as e:
Expand All @@ -38,6 +44,10 @@ def convert_image_attachments(env):
attachment.res_id,
repr(e),
)
# flush and clear cache to avoid to fill up memory and force the
# computation of the computed fields (smaller size images)
Model.flush()
env.cache.invalidate()


def move_fields_from_invoice_to_moves(env):
Expand Down
Loading