HALIFAX -- Nova Scotia's highest court has ordered a new trial for a sex worker convicted of assault for stabbing a client she said was sexually assaulting her.

The woman had been convicted for stabbing Douglas Barrett in the back in his Sydney, N.S., home on Sept. 19, 2015.

They had known each other for "quite a while," but she testified at trial that she was afraid of Barrett, who had a reputation for mistreating and abusing some sex workers. But she had agreed to go with him in order to get money she needed for drugs.

The woman, who is Aboriginal, testified that she took a knife with her when Barrett asked her to go upstairs to his bedroom early in the morning.

She said he forced himself on top of her despite her repeatedly saying "no," and drove a knife in his back in self-defence.

"I said no. I said I, I wanted to leave. I told you I wanted to leave, just let me go. And he's like no we could just fool around for a bit," the woman testified, according to the Court of Appeal ruling.

"And that's when I had grabbed the knife and I had poked him in the back with it. He was on top of me."

After the stabbing, the two fought for control of the knife, and the woman fled the home. Barrett was taken by ambulance to hospital, where he was treated for a collapsed lung and numerous cuts.

Judge Alain Begin of the provincial court rejected the self-defence argument and found the woman guilty of assault causing bodily harm.

Begin acknowledged that Barrett was likely a predator, and may have been abusive to other sex workers, but said the woman had brought the knife upstairs even though he had not yet threatened her.

"Predators are also afforded protection under the law," said Begin. "They can't be attacked any more so than the prostitutes can."

Begin said the stabbing was "the first violent act," but the Nova Scotia Court of Appeal disagreed in a ruling released Wednesday.

"The first violent act was not, as the trial judge isolated, the stabbing of Mr. Barrett, but rather his sexual assault of the appellant. She was entitled to defend herself against this assault," the ruling said.

In the decision, the three-judge panel said the trial judge erred in his application of the laws of self-defence and consent.

"His errors had a critical effect on his assessment of reasonableness and, therefore, on the verdict," they wrote.

They allowed the appeal and have ordered a new trial. No date has been set.

The woman had been sentenced to 300 days plus one day, which were offset by her 300 days on remand and one day served in court for the sentencing.