In my opinion, the "Treaty of Non-Agression" was more a result of the refusal of the western powers to ally themselves with the Soviet Union and carry through the policy of "Collective Security".
England, France and the USA . . . draw back and retreat, making concession after concession to the aggressors… The chief reason is that the majority of the non-aggressive countries, particularly England and France, have rejected a policy of collective security, the policy of collective resistance to the aggressors, and have taken up a position of non-intervention, a position of “neutrality”. - J Stalin
You can also read this news article titled "Stalin’s plan to stop Hitler foiled when British talks broke down". It points out that Stalin had attempted to forge an alliance with the western powers to launch a pre-emptive strike on Nazi Germany barely a week before the Molotov-Ribbentrop pact was signed. I guess the loss of Spain also played into it but I just think that what I mentioned above had more of an impact on that decision.