Backported #7072 to 3-2-stable. Use database value for uniqueness validation scope.