An ancestor of this phrase is "
Thank heaven for
small mercies". It's often used sarcastically to express
relief that an unpleasant person or situation is avoided or gone.
"That annoying student finally moved to another
state," the secretary told the
principal.
"Thank God for
small favors," replied the Principal.