SAN FRANCISCO — A federal judge has refused to throw out a lawsuit brought by the family of Kate Steinle that alleges the U.S. government was negligent in her 2015 shooting death because the gun that killed her was left vulnerable to theft by a federal officer.

“A handgun is indisputably capable of inflicting serious injury and damage — as a deadly weapon, that is its very purpose,” U.S. District Court Judge Joseph Spero wrote in a 49-page decision released late Friday.

Leaving “a loaded gun in a backpack visible on the seat of an unattended vehicle in San Francisco ―create[s] foreseeable risk of harm,” the judge wrote. The Bureau of Land Management “ranger therefore had a duty to better secure his handgun against theft.”

But in response to a motion from the government, the judge dismissed portions of the suit that alleged the San Francisco Sheriff’s Department and U.S. Immigration and Customs Enforcement mishandled the custody arrangements for the man charged in Steinle’s killing.

Steinle family lawyer Frank Pitre declined to comment on the ruling Monday afternoon.

Lawyers for San Francisco and the U.S. government did not respond to messages.

Steinle’s July 1, 2015, killing made national headlines after a Mexican national who had been repeatedly deported from the country was arrested in the shooting. Juan Francisco Lopez Sanchez has pleaded not guilty in the criminal case, saying he found the gun and it accidentally fired a bullet that ricocheted off a San Francisco pier, striking Steinle in the back as she walked with her father.

The lawsuit alleged that both San Francisco and ICE contributed to the killing because they failed to detain Lopez Sanchez, an illegal immigrant who was released onto San Francisco streets after he was carted here from federal prison to answer a decades-old minor drug case.

The judge ruled San Francisco didn’t have a legal duty to cooperate with ICE as the suit alleged. That opened the door for former Sheriff Ross Mirkarimi to follow the city’s Sanctuary City rules by ignoring the federal agency’s detainer request asking that it be notified of when Lopez-Sanchez would be released. Mirkarimi has said he had no duty to do as ICE asked and wouldn’t have held Lopez-Sanchez without an order from a judge.

Mirkarimi had no mandatory duty to set “limits on cooperation with ICE detainer requests, and Plaintiffs therefore cannot base a claim on breach of such a duty,” the judge ruled.

During the presidential campaign, Donald Trump blasted San Francisco’s immigration policies and pointed to Lopez Sanchez as the type of dangerous criminal he intended to keep out of the country by building a wall at the Mexican border.

The president-elect has declared that local agencies that harbor people in the country illegally will be cut off from federal aid when he takes office Jan. 20.