Answer: It is still very controversial to say that heart surgery will change a person's personality.
However, our brain is under tremendous stress & risks during operation and peri-operative period.
Firstly, the patient will be given, sedation, pain killer, anaesthetic agent, blood thinning medications, cardiac medications etc. Some of these agents may affect our sensorium or reaction time.
Secondly, if the surgery involves temporarily stopping the heart, a extracorporal circulation is needed.
That is our circulation undergoes oxygenation and blood circulation with the help of specialized machines.
This could involve some risks, though infrequently, such as block clot, air bubbles being formed and lodge in the brain, hence resulting in some personality changes.