A federal judge in California on Thursday upheld two of the state's "sanctuary laws" that the Justice Department had challenged as unconstitutional, and partially upheld a third.

US District Judge John Mendez, who sits in Sacramento, found that two of the laws — one restricting local law enforcement cooperation with federal immigration authorities, and the other requiring state oversight of facilities that house federal immigration detainees — were "permissible exercises of California's sovereign power."

Mendez partially upheld the third law, AB 450, which regulates interactions between private employers and federal authorities. The judge wrote that the state could require employers to notify employees about upcoming workplace inspections, but he struck down sections that barred employers from voluntarily giving federal agents access to employee records or nonpublic spaces, as opposed to requiring a warrant or a subpoena.

The judge ended his opinion with a plea to Congress to pass immigration legislation. A "long-term solution to the problems our country faces with respect to immigration policy ... cannot and will not come from piecemeal opinions issued by the judicial branch," Mendez wrote.

"Accordingly, this Court joins the ever-growing chorus of Federal Judges in urging our elected officials to set aside the partisan and polarizing politics dominating the current immigration debate and work in a cooperative and bi-partisan fashion toward drafting and passing legislation that addresses this critical political issue. Our Nation deserves it. Our Constitution demands it," the judge wrote.

The ruling is a loss for Attorney General Jeff Sessions, who has made an aggressive push against so-called sanctuary laws. In announcing the lawsuit against California in March, Sessions accused state officials of “actively obstructing federal law enforcement," and said that he could not "sit idle while the lawful authority of officers is being blocked by politicians.”

Justice Department spokesperson Devin O'Malley said in a statement that they were disappointed in decision, but praised the judge's decision to strike down provisions that restricted employer cooperation with federal authorities.

"When they passed SB 54, AB 103, and AB 450, California’s political leadership clearly intended to obstruct federal immigration authorities in their state. The preliminary injunction of AB 450 is a major victory for private employers in California who are no longer prevented from cooperating with legitimate enforcement of our nation’s immigration laws. While we are disappointed that California’s other laws designed to protect criminal aliens were not yet halted, the Justice Department will continue to seek out and fight unjust policies that threaten public safety," O'Malley said.

"The Constitution gives the people of California, not the Trump Administration, the power to decide how we will provide for our public safety and general welfare. California’s laws work in concert—not conflict—with federal law," Becerra said.

The Justice Department argued California's laws violated the US Constitution's Supremacy Clause, which broadly states that when state law conflicts with federal law, federal law wins. Mendez wrote that while the federal government's "broad power" over immigration policy is "undisputed," that did not mean states lacked any authority to pass any immigration-related regulations.

The judge upheld SB 54, which blocks state and local law enforcement from sharing certain information with federal agents, such as when a person suspected of being in the United States illegally would be released from state custody.

The Justice Department argued SB 54 conflicted with federal law that prohibits states from withholding "information regarding the citizenship or immigration status, lawful or unlawful, of any individual." California argued that the federal law cited by DOJ, referred to as Section 1373, was unconstitutional and ran afoul of Supreme Court precedent that limited how much Congress could exercise control over the activities of state legislatures.

Mendez wrote that Section 1373 was "highly suspect." But he avoided the bigger constitutional question by finding that it did not conflict with SB 54. The judge adopted a narrow interpretation of Section 1373, holding that it applied "strictly" to immigration status, and not the other kind of information covered by SB 54.

Mendez disagreed with the government's argument that California's law was an unlawful "obstacle" to federal law enforcement.

"But refusing to help is not the same as impeding," Mendez wrote. "Federal objectives will always be furthered if states offer to assist federal efforts. A state’s decision not to assist in those activities will always make the federal object more difficult to attain than it would be otherwise. Standing aside does not equate to standing in the way."

The Justice Department failed to address California's interest in its relationship with the state's immigrant communities, the judge wrote. It was "entirely reasonable" for state officials to decide that helping federal immigration authorities would be a negative use of state resources, he said.

On AB 103, which directed the California attorney general to review facilities in the state that held immigration detainees, Mendez wrote that the law was different from state licensing regulations that were previously struck down. A review by state officials did not impose any actual burden on the federal government, he found.

"For all its bark, the law has no real bite. It directs the Attorney General to channel an authority he already wields to an issue of recent State interest. The facility need only provide access for these reviews, which is of little or no consequence," Mendez wrote.

On AB 450, which concerned private employers' interactions with federal immigration authorities, Mendez wrote that the prohibitions on giving authorities voluntary access to employee records and nonpublic areas violated the Supremacy Clause because of the thousands of dollars in fines employers faced if they granted access to the feds. The fines were a "clear attempt" to "meddle" with federal enforcement activity, the judge found.

But the judge upheld a separate section of AB 450 that required employers to tell employees about an upcoming employment eligibility inspection within 72 hours of learning about it. The Justice Department argued that giving employees advance notice would undermine federal investigations, but Mendez wrote that the government's position "convolutes" the purpose of the federal law that provides for such inspections. The law targets employers, not employees, the judge noted — "The 'targets' of the investigation have thus already been 'warned,'" he wrote.

"The Court declines to adopt Plaintiff’s cynical view of the law. As [friend-of-the-court briefs] point out, notice provides employees with an opportunity to cure any deficiencies in their paperwork or employment eligibility," Mendez wrote. "Federal law affords such a courtesy to employers; the Court does not view an extension of that courtesy to employees as an attempt to thwart [the Immigration Reform and Control Act's] goals."

The California case was the Justice Department's most direct challenge to date against jurisdictions that have adopted variations of sanctuary laws. When the lawsuit was filed in March, a senior Justice Department official told reporters that the department was in the process of reviewing immigration laws elsewhere. No other case has been filed so far.