Democrats in the House had a rare victory this week when an ugly, discriminatory amendment, backed by House Speaker Paul Ryan and pushed by Vice President Mike Pence, failed because 24 Republicans joined every single Democrat in beating it back. It was a pleasant surprise. And there’s an important takeaway.

The amendment to the defense spending bill, titled “Prohibition of Department of Defense Medical Treatment Related to Gender Transition” and offered by Rep. Vicky Hartzler, a Missouri anti-LGBTQ Republican, would have denied medical treatment for gender transition for military personnel and their dependents. Transgender people currently serving in the military have been able to serve openly ― and receive the necessary medical care for transitioning ― since June of 2016, after the Obama administration lifted the ban on open service for current members, ending discharges and involuntary separation. Hartzler’s amendment was an outright attack on transgender people, promoted by the usual nasty band of homophobic, transphobic GOPers in the House who’ve had a stranglehold on the leadership for years. The amendment was allowed out of committee, and Ryan expected it to pass. Conservatives weren’t happy about what happened.

“It’s a major loss for Pence and the [GOP House] leadership,” Matt Thorn, executive director of OutServe-Servicemembers Legal Defense Network (SLDN), one of several groups that were lobbying vigorously against the amendment, told me regarding the narrow 209-214 vote.

Hartzler’s amendment was an outright attack on transgender people promoted by the usual nasty band of homophobic, transphobic GOPers.

And of course, it was a win for trans people. Advocates from the coalition of groups, including the American Military Partner Association, the Human Rights Campaign, the National Center For Transgender Equality and the ACLU, were fully engaged and fought hard, as did Democratic leaders in the House. Minority Leader Nancy Pelosi and Minority Whip Steny Hoyer spoke out, demanding the amendment be removed. “They are fighting to rip away the health care of thousands of brave service members.” Pelosi said. “This cowardly Republican amendment targeting transgender men and women in uniform effectively bans these patriotic Americans from serving their country.”

And they actually got the help of Defense Secretary James Mattis. CNN, citing congressional and Pentagon sources, reported that Mattis called Hartzler to pressure her to drop the amendment. (Mattis, citing service chiefs who wanted more time to prepare, had last month put off for six months a plan to allow new transgender recruits, something advocates weren’t happy about, though they expect him to follow through.) When that didn’t work, Mattis lobbied individual GOP House members to vote against the amendment.

“Mattis had far more influence here than the vice president did,” Thorn notes.

Democrats stuck together, standing up for what’s right but also for their base and it was the Republicans who went on the run.

That’s remarkable. In addition to exposing rifts within the administration, it reflects how, with Donald Trump’s approval numbers underwater, the White House has little sway right now among key House Republicans ― and it also reflects how far acceptance of transgender people has come. Most of the 24 GOPers who voted against the amendment, including Representatives Darrell Issa of California, Barbara Comstock of Virginia, and Carlos Curbelo of Florida, are vulnerable, in districts that Democrats will be confidently and aggressively targeting in 2018.

Since the 2016 election, we’ve heard ad nauseum from a subset of Democratic activists, pundits, and strategists that one reason Trump won is because Democrats are too focused on “identity politics,” or what Columbia University professor Mark Lilla, in a New York Times piece, derogatorily called a “fixation on diversity” and “identity drama.” In an op-ed two weeks ago in the Times, headlined, “Back to the Center, Democrats,” Mark Penn and Andrew Stein warned that Democrats had become “mired” in “transgender bathroom issues,” among other things, ignoring white “working class voters” who “feel abandoned.” It’s the same old mantra, which amounts to a call for pandering to bigotry.

in NYT, Penn warned Dems about supporting trans issues. note yesterday House GOPers in swingy districts didn't want to be on wrong side pic.twitter.com/USKLhQ4pce — Joe Sudbay (@JoeSudbay) July 14, 2017

But what happened this week proved, once again, that that kind of thinking isn’t just offensive; it’s bad political strategy. The Democrats stuck together, standing up for what’s right but also for their base ― which is a diverse and large coalition ― and it was the Republicans who went on the run.

In the face of the danger of a rollback not just on rights for queer people but for all minorities under attack in the Trump era, this showed that standing firm, energizing activists in the base and resisting ― rather than pandering and caving in ― is the way to win.

Follow Michelangelo Signorile on Twitter: www.twitter.com/msignorile