At the same time that the federal, Texas, and Houston governments were all working together to respond to the historic disaster that Hurricane Harvey and its aftermath have caused, they’ve all been at each other’s throats over a state immigration law that was poised to go into effect before the waters receded.

But Texas’s cities have just won a huge victory over the state (and the feds). On Wednesday night, federal judge Orlando L. Garcia of the Western District of Texas issued a ruling stopping most of the state’s “anti-sanctuary-city” law SB4 — which attempted to force local police departments to assist federal immigration enforcement — from going into effect as scheduled on Friday.

The ruling signals that the judge is likely to find that the provisions put on hold are unconstitutional. In the meantime, he’s stopping the state from enforcing them while he considers them more fully.

Texas Attorney General Ken Paxton has already vowed to appeal, arguing that the judge’s ruling — which essentially maintains the status quo — is making Texas “less safe.” The plaintiffs who sued to stop the law, meanwhile, including the governments of Texas’s major cities and immigrant-rights advocacy groups, are celebrating the ruling as a near-complete victory.

The ruling doesn’t stop every part of the law that had local police officers concerned. But it does prevent the Republican-dominated Texas state legislature from using immigration to punish Texas’s Democratic-controlled city governments. And it substantially reduces the scope of a law that, all told, would have expanded state enforcement of immigration law more than any other bill since Arizona’s SB 1070 “show me your papers” law from 2010. (The Arizona law made being in the state as an unauthorized immigrant a state offense and allowed officers to question people about their immigration status to enforce it; it was also largely put on hold by the courts, including the Supreme Court in 2012.)

For cities that are currently fighting both state and federal attempts to push them into collaborating with immigration authorities — not to mention the city in Texas currently trying to make sure its residents don’t literally drown in their homes — that’s a crucial respite.

The court ruled that local police must be allowed to ask people about their immigration status — but they can’t do anything beyond sharing information with ICE

The Texas law, Senate Bill 4, originated when the state government of Texas got angry with the new sheriff of Travis County (the county that includes state capital Austin) who decreed that county jails would stop honoring federal requests, known as detainers, to hold immigrants after they’d otherwise be released from jail so that federal agents could pick them up.

In retaliation, the governor stripped funds from the county government, and the legislature designed SB4 — a law that would have allowed them to criminally charge local officials for doing something the state felt would limit immigration enforcement.

SB4 doesn’t directly tell police officers and jail officials what they can and can’t do. Instead it prohibits local governments and police departments from setting policies which would set limits on helping the federal government deport unauthorized immigrants.

But the court, for the most part, said that the state’s efforts to dictate local policies were likely enough to be unconstitutional that they’d better not go into effect Friday.

Among the parts of SB4 that have been put on hold:

A provision that would have forced local jails to honor federal agents’ requests to hold immigrants after they’d otherwise be released, so that ICE could pick them up.

A provision that would have barred any local official from “endorsing,” or even appearing to endorse, any policy that would have materially limited immigration enforcement (including, possibly, standing on stage with advocacy groups that were advocating for such limits).

A provision that would have required local police to allow their officers to cooperate with federal agents whenever possible, including “enforcement assistance” of federal immigration law.

The court did not, however, enjoin one of the parts of SB4 that attracted the most controversy when the bill was passed earlier this summer: the provision that forces local police departments to allow officers to ask about the immigration status of residents during a detention or arrest.

The court’s ruling emphasizes that SB4 doesn’t allow officers to stop someone solely because they suspect the person to be an unauthorized immigrant. And if they ask about immigration status, the law doesn’t allow them to do anything with that information beyond sending it to ICE — they can’t hold onto someone they would otherwise let go while they wait to hear back from ICE about the detainee’s immigration status, for example.

But it’s not entirely clear, in practice, how much those safeguards actually mean. There’s some evidence that being able to ship people into ICE custody encourages racial profiling to begin with.

The cities and advocacy groups that sued over SB4, however, don’t see this as a huge setback. They argue that in practice, many police officers are already asking people about their immigration status, so SB4 doesn’t change much. The parts of the law the plaintiffs were worried about weren’t the parts that assisted cops who wanted to help enforce federal immigration law, but the parts that punished cops and departments who wanted to limit their cooperation with the feds to protect their relations with immigrant communities. And on that count, they believe they’ve won a huge victory.

Trust between immigrants and the government is still precarious in Texas

You could argue that Judge Garcia’s ruling is a rebuke not only of the state of Texas, but also of the Trump administration. After all, the Department of Justice submitted a brief in favor of SB4.

More importantly, the argument about whether local jails can be made to hold people for pickup by immigration enforcement is also at the crux of the ongoing “sanctuary city” battle between cities and the federal government, which is trying to withhold the biggest federal law-enforcement grant from any city that limits cooperation with detainer requests.

But this is just the first ruling in what’s sure to be an ongoing legal battle over SB4. Texas is sure to appeal the ruling to the Fifth Circuit Court of Appeals — a fairly conservative circuit court that may overturn some of Wednesday’s ruling. And the federal-local battle over defunding “sanctuary cities” is still in its very early stages.

In the meantime, law enforcement officials have to try to maintain good relationships with immigrant communities that have been worried about both SB4 and ICE raids. In Houston, that fear has been compounded with the emergency posed by Hurricane Harvey — local and state officials have tried to assure residents that shelters won’t check for immigration status, despite the fact that Border Patrol checkpoints remained open during the evacuation last week.

Legal battles over laws like SB4 can change at a moment’s notice — and laws can be stopped 36 hours before going into effect. But retaining the often-fragile relationship between unauthorized immigrants and local government, and repairing it if it’s broken, takes much longer.