Se rendre au contenu
Menu
Cette question a été signalée

Hi Odoo Community, 

I'm facing an issue while importing large datasets (e.g., thousands of records) using a cron job in Odoo, and this is specifically on Odoo.sh.

🧪 Scenario:
  • I upload a large CSV file (with 5000+ records).
  • A scheduled cron job runs every 5 minutes to process and create records in the database.
  • After some time (usually mid-process), the cron crashes with this error:

psycopg2.InterfaceError: cursor already closed

🔍 Observations:
  • The issue does not occur with small files (under 500 records).
  • It seems to be related to long-running loops, likely causing the DB session or cursor to close unexpectedly.
  • This happens consistently during large data operations on Odoo.sh and also in Local.
❓ My Questions:
  1. Why does the “cursor already closed” error occur during long cron executions in Odoo?
  2. Since I’m using Odoo.sh, I cannot modify server timeouts or configurations — what are the alternatives?
  3. What’s the best practice to safely process thousands of records in a cron job on Odoo.sh? and also in Local

Any help would be highly appreciated 🙏

Thanks in advance!

Avatar
Ignorer

If you are using a shared server on odoo.sh then you can't run long batch jobs. As a dedicated odoo.sh server is very expensive you probably need to look at other hosting options which allow you to have more control.

Meilleure réponse

You need to perform your import in smaller chunks.

We usually do this by just fetching a more reasonable number of lines from a large file and keep track of the last processed line once that chunk has been processed.

Now, by keeping track of the last record, you can utilize the ir.cron.trigger model. In here you would store the cron_id and a call_at datetime allowing you to continue with the next set of lines, once it's its turn.

This way you don't have to deal with manual cursor creation since each iteration of a cron task would just work on a limited number of records, safely process it, stop gracefully and the awaits the next trigger to run the cron task (starting from the last processed line + 1). This is logic you will have develop.

Avatar
Ignorer
Publications associées Réponses Vues Activité
1
juin 25
316
1
nov. 24
3828
1
juin 25
490
1
déc. 24
3223
1
janv. 25
1008