(CNN) Earlier this summer, Texas passed a law banning sanctuary cities. To guard itself against potential lawsuits, the state quickly went to court to get it declared constitutional before the law was even implemented.

But the pre-emptive effort backfired when, on Wednesday, a federal judge in Austin tossed the suit.

US District Judge Sam Sparks, appointed under Republican President George H.W. Bush, didn't rule on the legality of the measure. Instead, he said the state was acting prematurely.

The law doesn't go into effect until September 1.

"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 ruling said.

Read More