With impeachment quicksand swirling around President Trump’s feet, he might have been able to find some comfort in the fact that his Ukraine mess was serving a key political purpose. Until this week rolled around.

Trump wants to run against Elizabeth Warren, and since the Ukraine news has been highlighting Joe Biden’s son Hunter and his odd position at a Ukranian energy company, Trump seemed to be supporting that long-range goal by pressuring Biden — even though any focus on Ukraine was and is damaging to the president.

For various reasons, Biden’s star had been diminishing since Labor Day. Warren was rising in the polls, and while the ex-veep wasn’t really sinking, there seemed to be no excitement swirling around him.

At various points in the September and October debates, Biden didn’t sound particularly coherent. It emerged that he has had trouble raising money and was spending more than he raised.

In October, two national polls and two Iowa polls had Warren tied or slightly ahead of Biden for the first time. On Oct. 8, she took the lead in the RealClearPolitics average, 26.6 percent to 26.4 percent.

Then Bernie Sanders had a heart attack and lied about it for three days, thus suggesting he was not long for the race and that the progressive “lane” he and Warren were splitting would end up moving into her column and putting Biden away.

And Biden seemed unable to turn the tables on Trump’s personal attacks on his only living son. He tried to make an emotional case as a still-grieving father of a son who had died only four years ago. Trump’s attacks, Biden insisted, should be considered beyond the pale. But all that only underscored the irregularities in Hunter’s conduct.

Last week, everybody in the know was already operating on the assumption that Biden was finished. Oh, his run would continue and all that, but he was on the downward slope toward oblivion. And then …

Well, if you’re Warren and you live by the polls, you also have to take the heat from the polls. This week, both Survey USA and CNN have Biden up by an astonishing 15 points over Warren.

CNN has Biden at 34 percent to 19 percent (albeit with a very large margin of error, nearly six points). Survey USA has it at 33 percent to 18 percent. If those seem like crazy outliers, consider that Politico has the national race with Biden ahead by nine points and The Hill by eight. Only Emerson has it close, with Biden ahead by two points.

All these polls were taken after the Democratic debate last week, which is important. They suggest the general impression that Biden was terrible — though I wrote here that he had a great last half-hour — seems not to have been shared by anyone who already supported him or might have been mostly on his side.

More important, perhaps, Warren came under fire in the debate for the unrealistic and vague pie-in-the-sky promises she keeps making — and had no counterargument. That seems to have hurt her or at least stymied her momentum. It’s important to note that Biden was very effective in making that argument against Warren, which is why he had a great last half-hour.

Something else may be going on here, too: It may well be that the sense Biden hasn’t handled the Hunter allegations well is mistaken. Perhaps he is right to think that refusing to engage Trump much on the matter is the better strategy, because Democratic primary voters hate Trump so much their instinct is to embrace Biden rather than move away from him.

In which case, the only potentially positive news for Trump in the Ukraine mess may not be positive at all in the end. The American politician who looked like he was having the worst week last week now may be having his best week — and at just the right time.