OAKLAND — Oakland may have had a duty to enforce building and fire codes at the Ghost Ship warehouse, according to a significant court ruling that could eventually leave the city liable for 36 deaths in the horrific Dec. 2 fire.

The Nov. 8 decision by Alameda County Superior Court Judge Brad Seligman pierces through broad immunities protecting California cities from civil lawsuits in which workers botched inspections of a building or failed to perform the inspection at all.

In his tentative ruling, Seligman cited the allegations by attorneys for the families of the victims and said their civil lawsuit “exhaustively” documented the dangerous conditions of the Fruitvale district artist collective:

“The plaintiffs allege the city ‘knew in advance’ of the fire of various unpermitted uses and dangers, including a ‘likely risk of fire’ and that ‘in the evert (sic) of a fire occupants of the building were likely to die or suffer serious bodily injury due to the many violations of mandated building codes and safety provisions, all of which the city was aware of and required to enforce at all relevant times,’” Seligman wrote.

Stay up to date on East Bay news by downloading our mobile app for free. Get it from the Apple app store or the Google Play store.

The ruling wasn’t on the merits of the plaintiffs’ complaint but overruled a demurrer filed by the city of Oakland in opposition to the lawsuit. The judge said at this point, all allegations have to be considered until the facts of the case are argued. City spokeswoman Karen Boyd referred questions to the City Attorney’s Office, which did not respond to a request for comment on Tuesday.

Records show Oakland police, firefighters and building inspectors visited the warehouse before the December inferno, sometimes going inside the labyrinth-like collective stuffed with pianos and a maze of extension cords where more than 20 people illegally lived.

One firefighter admitted to attending a holiday party there in 2014 for the faculty of his wife’s school. The party was held on the second floor of the Ghost Ship, according to court records. In March 2015, a police officer shut down a wild rave there, telling partygoers he would report them to the city. The City Attorney’s Office is looking into a report by this newspaper in which multiple eyewitnesses said firefighters stopped by a September 2014 party at the warehouse. Yet a fire inspection was never performed at the warehouse, according to city officials.

Attorneys for the city argued any visits to the Ghost Ship amounted to an inspection. California government code shields public entities from liability based on a failure to inspect.

Mark Gergen, a UC Berkeley law professor who reviewed Seligman’s ruling, said the judge is “finding a rather creative exception to the immunity rule.”

“What the judge is doing is not alleging they were negligent in inspection but alleging they knew about this” and “it’s a failure to act,” Gergen said.

Oakland can appeal the court decision.

Get top headlines in your inbox every afternoon. Get the free PM Report newsletter.

“I fully expect the city to file an appeal at some point,” said Bobby Thompson, an attorney for the plaintiffs. “They feel they should be given a pass for these types of cases. We get to try to prove to the court that they failed to perform their mandatory duties under the law.”

For now, the city of Oakland remains a defendant in the massive civil lawsuit. Ghost Ship landlord Chor Ng, master tenant Derick Almena, Alameda County, PG&E and others are also listed as defendants.