AUSTIN, Texas ― The state’s lawsuit seeking preemptive court approval for a new law cracking down on immigration was dismissed on Wednesday, handing a victory to critics trying to overturn the measure.

The ruling by U.S. District Judge Sam Sparks ends an attempt by Texas Attorney General Ken Paxton (R) to head off legal challenges filed by several cities against Senate Bill 4, a Republican-backed measure that would criminalize so-called sanctuary policies.

Paxton filed the lawsuit hours after Texas Gov. Greg Abbott signed SB 4 into law, partly in an attempt to steer the inevitable legal challenges to what he suspected might be a more sympathetic venue. Sparks’ order, dated Tuesday but filed Wednesday, said Texas lacked standing to bring the lawsuit.

“The State’s own argument underscores its deficiencies,” the judge wrote. “Because SB 4 does not take effect until September 1, 2017, it is impossible for Defendants to take any action that would violate the not-yet-effective law. The mere fact that a municipal policy was instituted before a law was signed, or that it remains in place prior to the law taking effect, does not equate to a violation of the law.”

Austin City Councilman Greg Casar ― who has supported his county’s policy of limiting its cooperation with Immigration and Customs Enforcement detainers ― applauded the decision in a tweet, describing Paxton’s lawsuit as “frivolous.”

Breaking news! Federal Judge Sparks has dismissed @KenPaxtonTX frivolous lawsuit against me and my colleagues for our advocacy against #sb4 pic.twitter.com/vaRokKpbXG — Gregorio Casar (@GregCasar) August 9, 2017

Paxton bemoaned the ruling in a statement, but said he’d continue to defend the new law.

“We were first to file a lawsuit concerning SB 4, filed this case in the only proper court, and moved quickly to consolidate other lawsuits against SB 4 in Austin,” Paxton said. “The health, safety, and welfare of Texans is not negotiable. We’re disappointed with the court’s ruling and look forward to pressing our winning arguments in the San Antonio cases and beyond (if necessary) on this undoubtedly constitutional law.”

The challenges against the contentious state immigration crackdown will proceed in federal court in San Antonio. More than a half-dozen local governments ― including those of Austin, El Cenizo, Houston and El Paso ― accuse state lawmakers of forcing them to adopt policies that violate the Constitution.

The term “sanctuary city,” which some jurisdictions reject, generally refers to those that limit cooperation with deportation efforts in some way, or to those that instruct police not to ask suspects about immigration status. Proponents of the policies argue they improve public safety by making immigrants less fearful of local law enforcement. Local officials that limit cooperation with ICE also point out that some federal judges have ruled that holding people solely on an ICE request without a warrant is unconstitutional.

But SB 4 would make it illegal for local authorities to refuse requests to hand over undocumented immigrants in their custody to federal immigration agents. Officials who adopt such sanctuary policies would face the possibility of up to a year in prison, if the law goes into effect. The measure also allows Texas police to ask the immigration status of anyone they stop ― a provision that drew comparisons to Arizona’s 2010 state immigration crackdown bill, which was largely gutted by the U.S. Supreme Court.

The Texas immigration law is scheduled to go into effect on Sept. 1. But the spate of legal challenges may cause a delay.

All of the challenges to SB 4 have been consolidated into one case before U.S. District Judge Orlando Garcia in San Antonio. He held a hearing in June, but has yet to rule.

But earlier, in a separate case, Garcia decided that an undocumented immigrant’s Fourth Amendment right against illegal search and seizure was violated when he was held in a Bexar County jail on behalf of ICE. That ruling suggests the judge may be receptive to SB 4’s challengers.

The cities suing the state also argue that Texas doesn’t have the authority to come up with new immigration laws and penalties on its own, since only the federal government can regulate immigration.

The Trump administration has made a mission of stamping out sanctuary policies nationwide, with limited success. A federal judge temporarily blocked President Donald Trump’s executive order threatening federal funds for “sanctuary cities,” ruling it likely unconstitutional.

Attorney General Jeff Sessions has continued to threaten cities and counties with loss of law enforcement funding if they decline to fully cooperate with ICE, sometimes making misleading comments about the policies, federal law and academic studies.

On Monday, the city of Chicago sued the Trump administration to prevent it from withholding funds based on policies regarding immigrants and ICE. Sessions warned in a statement afterward that the ”administration will not simply give away grant dollars to city governments that proudly violate the rule of law and protect criminal aliens at the expense of public safety.”

Elise Foley contributed reporting.