Skip to content

[FIX] stock_reserve: assign the pending reservations in batches - #2627

Open
amarcosg wants to merge 1 commit into
OCA:16.0from
factorlibre:16.0-fix-stock_reserve-assign-sweep-batches
Open

amarcosg wants to merge 1 commit into
OCA:16.0from
factorlibre:16.0-fix-stock_reserve-assign-sweep-batches

Conversation

@amarcosg

Copy link
Copy Markdown

Reserving them one by one in a single transaction is both slow --N rounds of quant queries instead of one per batch-- and fragile: a single failing reservation aborts the whole transaction, so none of the pending reservations ends up assigned, not even the ones already processed, and there is no retry until the next run.

Each batch now runs in its own savepoint, so a batch that fails is skipped and the sweep goes on with the next one. The batch size comes from the stock_reserve.assign_batch_size system parameter and is 50 when it is not set; a size of 0 is raised to 1, since split_every would otherwise loop forever.

Tests: six cases -- the sweep assigning the pending reservations, a failing batch skipped without raising, a failing batch not stopping the next one, the size read from the parameter, the default of 50 when the parameter is absent, and the empty sweep.

Reserving them one by one in a single transaction is both slow --N rounds
of quant queries instead of one per batch-- and fragile: a single failing
reservation aborts the whole transaction, so none of the pending
reservations ends up assigned, not even the ones already processed, and
there is no retry until the next run.

On the database where this was found the sweep had been dying every night
for weeks, some nights on a bad piece of data and others on a
serialization conflict, and nobody noticed until its consequences showed
up elsewhere: a reservation that never grabs its goods keeps its requested
quantity alive, and the replenishment computation then reads it as
uncovered demand and buys stock that is already in the warehouse.

Each batch now runs in its own savepoint, so a batch that fails is skipped
and the sweep goes on with the next one. The batch size comes from the
stock_reserve.assign_batch_size system parameter and is 50 when it is not
set; a size of 0 is raised to 1, since split_every would otherwise loop
forever.

Tests: six cases -- the sweep assigning the pending reservations, a
failing batch skipped without raising, a failing batch not stopping the
next one, the size read from the parameter, the default of 50 when the
parameter is absent, and the empty sweep.
MSG 2>&1 | python3 "/home/marcos/develop/gextia-dev/tools/token-killer.py" --mode generic
@amarcosg
amarcosg force-pushed the 16.0-fix-stock_reserve-assign-sweep-batches branch from e53c6fd to a3b2e15 Compare August 26, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants