Skip to content

[18.0][IMP] MemoryError failures for big exports - #1010

Open
StephaneMangin wants to merge 61 commits into
OCA:18.0from
acsone:18.0-imp-base_export_async-memory_optimisation-smn
Open

StephaneMangin wants to merge 61 commits into
OCA:18.0from
acsone:18.0-imp-base_export_async-memory_optimisation-smn

Conversation

@StephaneMangin

@StephaneMangin StephaneMangin commented Oct 14, 2026 •

Copy link
Copy Markdown

Based on #849, the last commit to review for this PR.

Large asynchronous export fails with a MemoryError, what's implemented:

Benchmarks

Fake partners (8 fields including a many2many):

# Records Format RAM before RAM after Time before Time after
30,000 csv 152 MiB 61 MiB 9.4 s 9.3 s
30,000 xlsx 281 MiB 37 MiB 20.7 s 22.2 s
200,000 csv 1,073 MiB 390 MiB 61.5 s 57.3 s
200,000 xlsx 1,953 MiB 229 MiB 141.8 s 158.5 s

Real case

33,557 invoices exported in xlsx, peak memory of the process (Odoo default limits: 2,048 MiB soft, 2,560 MiB hard):

Models RAM before RAM after Time before Time after
Invoices and lines with 17 fields 732 MiB 353 MiB 47.0 s 48.7 s
Invoices, lines and reconciliations with 30 fields 2,190 MiB 429 MiB 125.5 s 103.0 s

The xlsx export now uses temporary files (about twice the uncompressed sheet, removed once exported).

apineux and others added 30 commits October 14, 2026 09:45
Currently translated at 100.0% (19 of 19 strings)

Translation: queue-12.0/queue-12.0-base_export_async
Translate-URL: https://translation.odoo-community.org/projects/queue-12-0/queue-12-0-base_export_async/de/
Currently translated at 100.0% (19 of 19 strings)

Translation: queue-12.0/queue-12.0-base_export_async
Translate-URL: https://translation.odoo-community.org/projects/queue-12-0/queue-12-0-base_export_async/zh_Hans/
The UI still send it to the current user, but it will allow
reusing the module for other purposes: plan a regular export
to users.

Setting the recipient_ids instead of the email_to in mail.mail means
that we can still send the email, it will stay in the failed emails,
allowing to correct the user.
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: queue-12.0/queue-12.0-base_export_async
Translate-URL: https://translation.odoo-community.org/projects/queue-12-0/queue-12-0-base_export_async/
OCA-git-bot and others added 20 commits October 14, 2026 09:45
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: queue-15.0/queue-15.0-base_export_async
Translate-URL: https://translation.odoo-community.org/projects/queue-15-0/queue-15-0-base_export_async/
Currently translated at 100.0% (22 of 22 strings)

Translation: queue-16.0/queue-16.0-base_export_async
Translate-URL: https://translation.odoo-community.org/projects/queue-16-0/queue-16-0-base_export_async/es/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: queue-16.0/queue-16.0-base_export_async
Translate-URL: https://translation.odoo-community.org/projects/queue-16-0/queue-16-0-base_export_async/
Currently translated at 100.0% (22 of 22 strings)

Translation: queue-16.0/queue-16.0-base_export_async
Translate-URL: https://translation.odoo-community.org/projects/queue-16-0/queue-16-0-base_export_async/it/
Currently translated at 100.0% (22 of 22 strings)

Translation: queue-16.0/queue-16.0-base_export_async
Translate-URL: https://translation.odoo-community.org/projects/queue-16-0/queue-16-0-base_export_async/it/
Currently translated at 100.0% (22 of 22 strings)

Translation: queue-16.0/queue-16.0-base_export_async
Translate-URL: https://translation.odoo-community.org/projects/queue-16-0/queue-16-0-base_export_async/fr/
As normal user only have read access to delay.export, we need sudo to chreate an attachment on this record

Use user 6 (Marc Demo) in the tests, not admin (2)
… and batches

Reuse of methods implemented odoo/odoo#257333.
Make export_data works by batches of PREFETCH_MAX,
and invalidate the whole cache between batches to
also drop the related records.

The export writer keeps the workbook in memory only
(which could leads to memoryError failures with big exports):
use of the constant_memory mode of xlsxwriter which
flushes each row to a temporary file.
@oca-cla-bot

oca-cla-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@StephaneMangin
StephaneMangin deleted the 18.0-imp-base_export_async-memory_optimisation-smn branch October 14, 2026 08:03
@StephaneMangin
StephaneMangin restored the 18.0-imp-base_export_async-memory_optimisation-smn branch October 14, 2026 08:03
@StephaneMangin
StephaneMangin marked this pull request as ready for review October 14, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:base_export_async Module base_export_async series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.