# Duplicate ref generated in llx\_paiement table (Dolibarr 21.0.0, PostgreSQL, possible race condition)

**URL:** <https://www.dolibarr.org/forum/t/duplicate-ref-generated-in-llx-paiement-table-dolibarr-21-0-0-postgresql-possible-race-condition/31150>\
**Category:** Developing for Dolibarr\
**Created:** [May 2, 2026, 4:20am UTC](https://www.dolibarr.org/forum/t/duplicate-ref-generated-in-llx-paiement-table-dolibarr-21-0-0-postgresql-possible-race-condition/31150 "2026-05-02T04:20:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarunno360](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@tarunno360](https://www.dolibarr.org/forum/u/tarunno360)\
**Post date:** [May 2, 2026, 4:20am UTC](https://www.dolibarr.org/forum/t/duplicate-ref-generated-in-llx-paiement-table-dolibarr-21-0-0-postgresql-possible-race-condition/31150/1 "2026-05-02T04:20:06Z")

</div>

I am encountering an issue where duplicate values are generated in the `ref` field of the `llx_paiement` (Payment) table.

### Environment

- **Dolibarr version:** 21.0.0

- **PHP version:** 8.2

- **Database:** PostgreSQL

- **Hosting/Setup:** Linux (Ubuntu 22 server)

### Problem Description

When creating payments, the `ref` value is occasionally duplicated. The issue appears to be related to very short time gaps between payment creations.

### Detection Query

```auto
SELECT *
FROM llx_paiement
WHERE ref IN (
    SELECT ref
    FROM llx_paiement
    GROUP BY ref
    HAVING COUNT(*) > 1
)
ORDER BY ref;

```

### Observations

- Duplicate `ref` values detected

- The issue occurs when two payments are created within a very short time interval (≈1 second or less)

- This suggests a possible **race condition in reference generation**

- The `ref` column does **not** have a UNIQUE constraint at the database level

### Questions

1. Is this a known issue in Dolibarr 21.0.0, especially with PostgreSQL?

2. Which numbering module is recommended to ensure unique payment references?

3. Does Dolibarr implement any locking or transaction-safe mechanism to prevent duplicate refs?

4. Would adding a UNIQUE constraint on `ref` be safe, or could it break standard behavior?

5. Is there any official fix, patch, or recommended workaround?

### Concern

I would like to avoid custom fixes that might create issues during future upgrades and prefer a standard/recommended solution.

Thank you for your support.

---

<div class="post-metadata">

**Author:** ![jonbendtsen](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jonbendtsen](https://www.dolibarr.org/forum/u/jonbendtsen)\
**Post date:** [May 2, 2026, 8:50am UTC](https://www.dolibarr.org/forum/t/duplicate-ref-generated-in-llx-paiement-table-dolibarr-21-0-0-postgresql-possible-race-condition/31150/2 "2026-05-02T08:50:08Z")

</div>

thank you for reporting. I wish I had your problem of too many payment creations within less than a second.

how do you get that? Are you using the API? Are you importing a file with payments?

If importing a file, my expectation is that it would be processed sequential and should not result in a race condition.  
Regarding the API, it is also my expectation that it would be sequential - unless you spawn more API calls in parallel, is that what you are doing?

Or, is it independent customers that uses the online payment module in parallel at the same time?

---

<div class="post-metadata">

**Author:** ![tarunno360](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@tarunno360](https://www.dolibarr.org/forum/u/tarunno360)\
**Post date:** [May 3, 2026, 8:27am UTC](https://www.dolibarr.org/forum/t/duplicate-ref-generated-in-llx-paiement-table-dolibarr-21-0-0-postgresql-possible-race-condition/31150/3 "2026-05-03T08:27:36Z")

</div>

No, we are not using any AP or importing a file with payments.

We receive payments by multiple reception at a time from different booth.

 ![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/7/78e5651290e4082ee342d32f3fab945415398ee0.png)

The same payment reference has been used for two different patients.

---

<div class="post-metadata">

**Author:** ![jonbendtsen](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jonbendtsen](https://www.dolibarr.org/forum/u/jonbendtsen)\
**Post date:** [May 3, 2026, 6:58pm UTC](https://www.dolibarr.org/forum/t/duplicate-ref-generated-in-llx-paiement-table-dolibarr-21-0-0-postgresql-possible-race-condition/31150/4 "2026-05-03T18:58:43Z")

</div>

how do you get that, is it the POS module?

---

<div class="post-metadata">

**Author:** ![tarunno360](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@tarunno360](https://www.dolibarr.org/forum/u/tarunno360)\
**Post date:** [May 6, 2026, 8:21am UTC](https://www.dolibarr.org/forum/t/duplicate-ref-generated-in-llx-paiement-table-dolibarr-21-0-0-postgresql-possible-race-condition/31150/5 "2026-05-06T08:21:27Z")

</div>

No jonbendtsen its not the POS module. Its just the billing module. which is created by generating worksheet –\> generating invoice —\> payment by the customer

---

<div class="post-metadata">

**Author:** ![tarunno360](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@tarunno360](https://www.dolibarr.org/forum/u/tarunno360)\
**Post date:** [June 3, 2026, 10:18am UTC](https://www.dolibarr.org/forum/t/duplicate-ref-generated-in-llx-paiement-table-dolibarr-21-0-0-postgresql-possible-race-condition/31150/6 "2026-06-03T10:18:04Z")

</div>

The worksheet mentioned here is actually a Dolibarr ERP order. Since we deal directly with patients, we have changed certain terms, such as renaming ‘customer’ to ‘patient’.

---

<div class="post-metadata">

**Author:** ![jonbendtsen](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jonbendtsen](https://www.dolibarr.org/forum/u/jonbendtsen)\
**Post date:** [June 3, 2026, 11:18am UTC](https://www.dolibarr.org/forum/t/duplicate-ref-generated-in-llx-paiement-table-dolibarr-21-0-0-postgresql-possible-race-condition/31150/7 "2026-06-03T11:18:34Z")

</div>

I think you should post this as a bug on dolibarrs github page under issues
