The immigration free-for-all that starts in Congress this week will test the character of House Speaker Paul Ryan, the courage of Republican moderates, the cunning of President Donald Trump and the sensibilities of the Democratic left.

The odds are that any deal will fall part, and all of the above will be losers. Washington will prove to be as dysfunctional as the public perceives.

If, however, those politicians rise above that standard, it could be a win for all but the immigration-haters. The “Dreamers,” those immigrants brought here as children and who are contributing members of society, wouldn’t face the threat of deportation, and there would be more resources for border security.

Democrats, with some Republican support, last month tried to get a deal for the Dreamers by holding up the bill to keep the government running. They were unsuccessful, and Senate Democratic leader Chuck Schumer, despite protests from immigration activists, wisely retreated.

A government funding measure was passed a few days ago with a promise that the Senate would take up immigration this week. The procedure is that if anything gets 60 votes, it passes. As for the House, Ryan has said only that it would take up a White House-supported measure.

Trump has been all over the lot. He has offered a proposal that, in addition to supporting Dreamers and a border wall, would beef up deportation police and cut legal immigration, among other measures that never could get through the Senate. What he wants is anything he can call a victory.

There are more than 60 votes in the Senate to protect dreamers, ideally on a permanent basis, and to provide more money for border security (while being purposefully vague on a wall), in addition to some other, small changes. This depends on two conditions. First, the bipartisan self-styled common-sense lawmakers, Republicans like Susan Collins and Lisa Murkowski and Democrats such as Joe Manchin and Chris Coons, have to stick together and ignore Trump and his tweets. Republican Sens. Lindsey Graham and Jeff Flake can offer expertise in complicated areas, and John McCain, while stricken with cancer in Arizona, can offer inspiration.

The other condition is that liberals recognize what is achievable, rather than hold out for the perfect, as is their wont, contending they can do better after a blue-wave midterm election in November. They should remember that the same argument was made in 2006. The wave came, but the next year a Ted Kennedy-John McCain-George W. Bush immigration reform was defeated in the Senate by four votes, including a “no” from Bernie Sanders. No major immigration legislation has passed since.

If successful in the Senate — the odds are no better than 50-50 — it would then be up to Ryan and the House. There is a bipartisan bill in the House, too, similar to what could pass the Senate, if it adds more money for border security. The speaker should guarantee a vote on that measure, which is being put forward by Republican Will Hurd, whose Texas district covers 800 miles along the border, and by Democrat Pete Aguilar of California.

If Ryan doesn’t do that, or if he works to pass Trump’s punitive measure, it would be the final chapter in selling his political soul. He presents himself as a disciple of the late Jack Kemp, an inclusive, avidly pro-immigration Republican. There is little chance Ryan will be speaker a year from now. He could announce his retirement this year. Or more likely he will run for re-election while continuing to raise tons of money for Republicans, and then quit after the election or be in the minority anyway. Can he stand up to Trump and the right-wing Freedom Caucus?

As for Trump, who knows? With him, it’s never about principle. It’s personal. Flake believes this may be one instance where Trump’s instincts are better than the advice he’s getting.

If the president could claim a legislative victory for his wall, which during the 2016 campaign he said Mexico would pay for, he could tame his base. He could learn a lesson on this kind of political maneuvering from Ronald Reagan, who faced a threat from his evangalical Christian supporters over his nomination of Sandra Day O’Connor to the Supreme Court. Trump isn’t as skillful.

As for the public, there is overwhelming support for the Dreamers and strong skepticism about a wall, but there is also backing for more border security. On other issues, a solid majority opposes cuts in legal immigration and prefers a tilt more to immigration based on skills rather than centered on families.

Even in Iowa, the home state of Republican Rep. Steve King — who, with Trump, is the foremost immigration basher — 62 percent of voters favor pursuing a pathway to citizenship and not just for Dreamers, according to a recent poll.

The next several weeks could produce a win-win plan for both sides. If this fails, hundreds of thousands of young Dreamers will live in the fear of deportation, immigration advocates once again will walk away empty-handed, Republicans will take a political hit, and Trump will have nothing but his bluster.

Email Albert R. Hunt at ahunt1@bloomberg.net. Follow him on Twitter: @AlHuntDC

To send a letter to the editor about this article, submit online or check out our guidelines for how to submit by email or mail.