Editor’s Note: Errol Louis is the host of “Inside City Hall,” a nightly political show on NY1, a New York all-news channel. The opinions expressed in this commentary are his own.

(CNN) —  

The federal government shutdown is an expensive, demoralizing inconvenience felt all across the nation, not just in Washington. So why didn’t legislators work overtime to arrive at a compromise?

The answer to that question is: the politics of the next election.

While several legislative leaders have tried mightily to hammer out a compromise in recent days – notably Republican Sen. Lindsey Graham of South Carolina and Democratic Sen. Dick Durbin of Illinois – most legislators, with an eye on the political calendar, seem more interested in spinning the looming shutdown than preventing it.

The predominant logic on both sides of the aisle seems to be: “if we can’t avoid a crisis, let’s make sure we can lay it at the doorstep of the rival party.”

There is a lot of blame to go around: government shutdowns are not fun or funny. During the 2013 shutdown, for instance, thousands of people were stranded inside Grand Canyon National Park, most of them employees of hotels, restaurants and other companies that operate inside the boundaries of the park. National parks lost $450,000 a day during the shutdown, and thousands of low-wage workers, lacking funding or a place to go, faced a serious food shortage.

Overall, the government lost more than $2 billion during the last shutdown, and $24 billion was shaved from national economic output.

And yet, members of Congress talked openly about voting – and then did so – in a way that ensured another shutdown.

Looming over the brinkmanship is the mix of hopes and fears about the fall congressional elections. A host of indicators suggest Democrats will make major inroads and possibly seize control of the House of Representatives.

On average, any president, Democrat or Republican, sees his party lose 36 seats in the House if the president’s popularity falls below 50%. With an anemic 37% approval rating, Trump is on track to see his Republican colleagues lose enough seats to flip control of the House.

Early indicators suggest a Democratic wave is building. Nationwide, 34 state legislative seats have flipped from Republican to Democratic in the last year, a trend underscored by the high-profile victory of a Democrat in the recent Alabama special election for US Senate.

Those numbers have emboldened Democrats, who feel the political wind at their backs and pressure from an energized, restive liberal party base.

Democrats calculated that they could play hardball and demand an extension of DACA, the controversial federal program that grants temporary residency to hundreds of thousands of undocumented immigrants who were brought to the United States as children.

Republicans encountered their own political imperatives. Among Republican voters, according to a recent Gallup poll, immigration is tied with “government dissatisfaction” as the number one national problem.

President Donald Trump rode to victory in the 2016 primaries on the signature issues of building a wall on the Mexico border and a now-famous call for “a total and complete shutdown of Muslims entering the United States until our country’s representatives can figure out what is going on.”

Even as they face the prospect of a Democratic wave in the fall, Republicans have to face a party base demanding a crackdown on immigration. And GOP members who vote for “amnesty” for DACA recipients run the risk of facing primary challenges from other Republicans.

So the scene was set for a government shutdown that nobody wanted – but got anyway. It’s a case, all too common in Washington, where the needs of the politicians and those of the people are on a collision course.

This commentary was updated to reflect the government shutdown.