Updated

A federal judge blocked enforcement of much of a “sanctuary cities” law in Texas on Wednesday night, just days before it was set to go into effect.

U.S. District Judge Orlando Garcia blocked portions of Senate Bill 4 (SB 4) requiring local law enforcement departments to comply with federal requests to hold unauthorized immigrants in custody. Also blocked: a provision that stopped local departments from implementing policies that would “materially limit” enforcement of immigration laws, the Dallas News reported.

An aspect of the law permitting police officers to ask about immigration status was not blocked, but the ruling did limit the actions officers would be allowed to take after learning that a person was undocumented – officers could only report the person’s immigration status to federal authorities.

SB 4 had been cheered by President Donald Trump's administration but criticized by immigrants' rights groups who say it could force anyone who looks like they might be in the country illegally to "show papers."

"In sum, SB 4 gives local officers discretion to inquire and share information but it does not provide them with discretion to act upon the information that they may obtain," Garcia wrote.

sanctuary cities

In this June 26, 2017, file photo, Lydia Balderas, left, and Merced Leyua, right, join others as they protest against a new sanctuary cities bill outside the federal courthouse in San Antonio. (AP Photo/Eric Gay, File)

The measure passed the Republican-controlled Legislature despite months of protests and opposition from business groups who worried that it could cause a labor-force shortage in industries such as construction. Opponents sued, arguing it violated the U.S. Constitution. The ruling in San Antonio keeps it from taking effect as planned on Sept 1., allowing the case time to proceed.

HOUSTON MAYOR PROMISES ILLEGAL IMMIGRANTS FLEEING HARVEY WILL NOT BE TURNED OVER TO ICE

In a 94-page ruling, Garcia wrote that there "is overwhelming evidence by local officials, including local law enforcement, that SB 4 will erode public trust and make many communities and neighborhoods less safe" and that "localities will suffer adverse economic consequences which, in turn, will harm the state of Texas."

"The Court cannot and does not second guess the Legislature," he continued. "However, the state may not exercise its authority in a manner that violates the United States Constitution."

“The court was right to strike down virtually all of this patently unconstitutional law," the American Civil Liberties Union (ACLU) said shortly after the decision was announced. "Senate Bill 4 would have led to rampant discrimination and made communities less safe. That’s why police chiefs and mayors themselves were among its harshest critics — they recognized it would harm, not help, their communities.”

The Trump administration has targeted "sanctuary cities" throughout the U.S. while Attorney General Jeff Sessions has threatened to pull federal money from jurisdictions that hinder communication between local police and immigration authorities and has praised Texas' law.

The Associated Press contributed to this report.