Skip to Content
Menu
This question has been flagged

Hello,

I am in the process of building a controller which has multiple endpoints. Sometimes 2 endpoints are called within milliseconds of each other, these endpoints will create a customer if one doesn't already exist in the database. I tried to use time.sleep() to delay one of the threads but I have realised that the request.env variable does not get notified/updated when a process is carried out on another env variable. 

Is there any way to update the environment in a sense?

I see two other ways of potentially doing this which are:

  1. Querying the database directly with SQL commands

  2. Creating the data in a custom model which will then be picked up by a Cron job so they are all on the same thread, thus the same environment. 

Both of these options create a bit more work than I would like compared to finding a way to update the environment. 

Any suggestions would be greatly appreciated.

Thanks, 

EDIT: 

When I run: env.cr.commit() it seems to work but after reading this I am not sure whether this would be safe. 

When I start with env.cr.autocommit(True) this seems to work as well and I am not manually committing each time, could anyone spread some light on any risks related to cr.autocommit?

Or is only turned off by default to save on speed and memory?

Avatar
Discard
Related Posts Replies Views Activity
0
Apr 16
2910
0
Feb 19
4162
3
Jun 24
1836
0
Apr 24
560
1
Mar 23
1967