Where it gets interesting is when the priest no longer believes or believes in error. The personal state of grace of the priest is irrelevant. If the priest intends to do what the Church believes, his personal belief does not matter. Ex opere operato.
BUT, if the priest no longer believes what the Church believes it calls into question whether what he does is “what the Church intends” It is, at least, possibly invalid.
Several folks on this board have confused the Donatist heresy under such circumstances. The Donatists were simply weak. They offered incense to the Emperor yet really continued to believe. Further, personal sin - such as sexual sin - does not mean the priest no longer believes.
However, the actual disbelief by some priests in the Real Presence does raise issues of potential invalidity. Disbelief in the Divinity of Christ similarly impacts validity. Schisms over issues such as Papal Authority do NOT call into question validity per se since that issue is not directly related to the intent of the priest as to the sacrament. But when you get one of those priests who public assert their disbelief - you’ve got to wonder.