If you just go with the flow, and are reasonably competent, changes in faction dynamics usually wash over you. You end up taking orders from someone else, every now and then, but if blame needs to be pinned on someone, there tend to be juicier targets.
I was hired at my previous job by a departing manager who just lost his struggle against our new manager. I managed to finish my job, extend the solution to other teams (as mine went from 12 devs, a handful of Indian support, an Indian QA and PM, to a dev and two level2 support). It was probably my most painful job yet, I regressed, I didn't really 'finish' in the sense that it lacked documentation, good CD pipeline and minor tweaking to make it more efficient, and I hated the last months with my whole being. But politics didn't touch me.