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
SELECT *
FROM llx_paiement
WHERE ref IN (
SELECT ref
FROM llx_paiement
GROUP BY ref
HAVING COUNT(*) > 1
)
ORDER BY ref;
Observations
-
Duplicate
refvalues 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
refcolumn does not have a UNIQUE constraint at the database level
Questions
-
Is this a known issue in Dolibarr 21.0.0, especially with PostgreSQL?
-
Which numbering module is recommended to ensure unique payment references?
-
Does Dolibarr implement any locking or transaction-safe mechanism to prevent duplicate refs?
-
Would adding a UNIQUE constraint on
refbe safe, or could it break standard behavior? -
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.





