The White House barred Labor Secretary Raymond J. Donovan, who is under investigation for allegedly corrupt union dealings, from going before a Senate subcommittee yesterday to testify on a labor anti-racketeering bill.

Donovan was scheduled to appear in person to endorse legislation, S. 1785, calling for the automatic suspension of union leaders found guilty of corruption in office. But the administration late Tuesday afternoon advised Donovan not to appear, because, as one administration source said, "It would have been a horrendous idea."

"It would have been a gutsy thing for him to appear . . . He's that kind of a guy. But in this town, it also would have been a naive thing to do," the administration source said.

Vernon Louviere, Donovan's chief spokesman, declined comment on the cause of the secretary's abruptly canceled date with the subcommittee. However, Louviere confirmed that Donovan was planning to appear in person until late Tuesday afternoon.

Donovan had also canceled an appearance before the subcommittee on Jan. 27. The reason given then was that the departments of Labor and Justice had not worked out differences over the proposed anti-racketeering legislation. The departments had worked out those differences by yesterday. Donovan was going to say that to the subcommittee. Instead, the secretary's 14 pages of prepared comments were read to the subcommittee by Labor Department Solicitor T. Timothy Ryan.

In his prepared text, Donovan called the proposed legislation "one of the most important pieces of reform . . . affecting American workers to be considered by Congress in a number of years."

The proposed law, called the "Labor Management Racketeering Act of 1981," would establish as a felony an act in which an employer pays a bribe--for "labor peace," for example--of $1,000 or more to a union representative. A union official convicted under the law could be suspended from office for up to 10 years.