The school district and sheriff’s office in the Florida county that is home to Marjory Stoneman Douglas High School had no constitutional duty to protect the students there during the deadly February massacre, a federal judge has said in a ruling.

The decision was made in a lawsuit filed by 15 students who said they suffered trauma during the Feb. 14 attack in Parkland, Florida. A total of 17 students and staff members lost their lives; 17 others were injured.

Prosecutors are seeking the death penalty for Nikolas Cruz, 20, the former Stoneman Douglas student who is accused of opening fire at the school on Valentine’s Day. He has pleaded not guilty, but his lawyers have said he would plead guilty in exchange for a life sentence.

The Dec. 12 ruling, by Judge Beth Bloom, came on the same day that a county judge, Patti Englander Henning, came to the opposite conclusion. Henning found that Scot Peterson, the armed sheriff’s deputy who heard the gunfire but did not run in and try to stop the attack, did have an obligation to confront Cruz.

The two decisions in rapid succession highlight an assumption often made: the belief that the public has a right to receive protection from police officers.

But police officers, in fact, generally are not under any legal obligation to protect citizens who are not in their custody.

“Neither the Constitution, nor state law, impose a general duty upon police officers or other governmental officials to protect individual persons from harm — even when they know the harm will occur,” said Darren L. Hutchinson, a professor and associate dean at the University of Florida School of Law. “Police can watch someone attack you, refuse to intervene and not violate the Constitution.”

The Supreme Court has repeatedly held that the government has only a duty to protect persons who are “in custody,” he pointed out.

“Courts have rejected the argument that students are in custody of school officials while they are on campus,” Hutchinson said. “Custody is narrowly confined to situations where a person loses his or her freedom to move freely and seek assistance on their own — such as prisons, jails or mental institutions.”

There are exceptions, Hutchinson said, as when a crossing guard who is specifically assigned to protect children traveling across a street allows a child to get run over while, say, the guard is being distracted by a smartphone. The crossing guard is in a “special relationship” with the children, in legal eyes.

When an officer has a “special relationship” with people, or acts to “enhance the risk” of harm, the officer can be liable for any resulting injury under state negligence laws, Hutchinson said.

This is likely how Henning found that Peterson did have a duty to protect those inside the school and refused to dismiss the negligence lawsuit filed by Andrew Pollack, whose daughter Meadow was killed.

The county lawsuit argued that Peterson had a “special relationship” with students and staff members at the school because he was specifically assigned to offer them protection.

Video footage and other evidence shows Peterson, the only armed officer at the school, staying outside while shots could be heard exploding from inside the school. Peterson also launched a “code red” to put the entire school on lockdown.

“They also argued that he enhanced the risk of death, or injury, by Cruz by negligently ordering a lockdown, which prevented escape from the building,” Hutchinson said. “Either of these assertions could support liability for Peterson. But I would not be surprised if the state case was reversed on appeal. It is very difficult to establish liability in this area of law.”

The federal decision is expected to be appealed.

A state commission that has been investigating the attack found last week that there was a multitude of failures on the part of the school and law enforcement officials in the response to the shooting.

At least eight sheriff’s deputies who raced to the school and heard gunshots stayed outside the building, the commission wrote in a 400-page draft report, and officers lost even more time scrambling to retrieve bulletproof vests from their cars.