An Ontario man who thought he was the proud father of an infant son—only to discover his wife had an affair and the little boy isn’t his—can take some small comfort in this: a judge has ruled he doesn’t have to pay child support.

In a court challenge that seemed to smack of desperation, the man’s now-ex-wife argued that although a DNA test confirmed he is not the biological father, he should still be on the hook for support payments because “he stood in the place of a parent” until the boy was three years old—when the truth finally emerged and their marriage crumbled. That her former husband has no genetic link to the child is irrelevant, she claimed.

The Supreme Court of British Columbia sided with the “sadly deceived” ex-husband (identified only as “P.Z.” in order to protect the privacy of the boy, known as “D”). It would not be “the least bit just, appropriate or fair” to force the “crestfallen” man to financially support the child, wrote Justice Robin Baird, in a decision posted this week. “[T]he whole thing was based on a serious and fundamental misapprehension of fact.”

Another fact: the judgment is not the legal no-brainer it appears to be. Though rare, similar disputes have landed in Canadian courtrooms before, and the case law is extremely clear: a person in P.Z.’s shoes—duped into believing he’s a dad, only to learn the real story years later—can still be held liable for child support. In the eyes of the law, the key question is not whether such payments are fair to the man who lived a lie. What matters most, as always, are the best interests of the child.

In fact, Justice Baird concluded that P.Z. does meet the legal definition of someone who “stood in the place of a parent,” a designation that automatically triggers child-support obligations. Fooled or not, the judge explained, the man loved and provided for the boy in “every respect as his own son” and “believed him to be his natural child.” His name even appears on the boy’s birth certificate.

When the time came to calculate a dollar figure, however, Justice Baird exercised his discretion under federal child-support guidelines and set the amount at zero—in large part because he wasn’t very impressed that Mom, identified as “E.Z.”, chose to drag only her ex-husband to court. Why, the judge wondered, has she not appeared to pursue payment from the the boy’s biological father?

“The claimant has provided no evidence at all concerning the circumstances of D’s conception, or who the natural father is or might be, where he lives, or what efforts, if any, have been made to identify, locate, or notify him of his lawful obligation to provide support for the child,” Baird wrote in his Feb. 10 ruling. “Similarly, although it seems that the claimant has re-partnered and D has been integrated into a new household with another man standing in the place of his parent, I have been told nothing about this man’s circumstances, his finances, or his ability to satisfy D’s material needs.”

Now approaching his 8th birthday, the boy was born somewhere in Ontario on March 30, 2009. Three years later, in June 2012, his mother and supposed father signed a separation agreement, specifically stating there were no children from the marriage. Clearly, P.Z. figured out by then he was not the boy’s biological father, and E.Z. had acknowledged it. Any shred of doubt was put to rest one year later, when a DNA test affirmed the truth.

“Not surprisingly, the respondent was crestfallen and felt upset and betrayed,” Baird wrote.

By that point, P.Z. was already long gone from the family picture, having last seen D when he was about 3½. The couple officially divorced in September 2014, and mother and son soon left for a new life in British Columbia. Another 18 months would pass before E.Z. served P.Z. with her sudden demand for child support.

In a landmark ruling released in 1999, the Supreme Court of Canada clarified the definition of a person who stands in the place of a parent—making clear that once such a bond is established, it “cannot be unilaterally withdrawn by the adult.” Factors to consider include whether a person provided monetary support, disciplined or guided the child, or represented to “the world, either explicitly or implicitly, that he or she is responsible as a parent.” In the case of a step-parent, the courts will also consider how the child viewed the relationship.

In other words, biology is only one part of the equation—which means all those other factors still apply to a father who suddenly learns, as P.Z. did, that he’s not the biological father.

Such was the case in 2000, when a Nova Scotia man discovered his twin sons were not really his. A court later decided the man should nevertheless pay monthly child support (albeit far less than the federal guidelines suggested) because he raised the boys for more than a decade and they still considered him their dad. As the judge noted, the twins loved him so much “there could be no more complete father and son relationship.”

Five years later, the Ontario Court of Justice presided over a similar divorce case, issuing a ruling that best captures the current state of the law. “To permit a father, in a sense, to ‘backdate’ his decision to parent the children ignores completely the reality of the children’s lives,” wrote Madam Justice June Maresca. “Although the father may have made a different decision had he been advised of the facts at the time of the child’s birth, the fact is that he was a parent to the child for many years. The emotional bonding, shared memories and trust that was built up over time cannot be wiped out with the stroke of a pen.”

Noting that “every case must be determined on its own facts,” Baird concluded that P.Z.’s circumstances differ somewhat from previous examples. For one, he and the child “have now been estranged for longer than they lived together,” raising doubts that the boy “formed any durable expectations of” the man who once considered him a son. “I also bear in mind that the claimant has moved across the country in order, I infer, to make a clean break with her past,” the judge continued, “and there is no desire on either side for renewal of any relationship between the respondent and the child.”

More than anything, though, Baird rejected the suggestion that P.Z.–“the abandoned non-biological parent”—should bear the burden of full financial support, especially in “the complete absence of evidence concerning the means and circumstances of other parents who owe a legal duty to meet the needs of the child.”

In the end, it’s Mom who will be forking over a cheque—to cover her ex-husband’s legal costs.