(a) No payment by the owner to any contractor or subcontractor of any part or all of the contract price for the erection and construction of any building, structure or improvement appurtenant to a building, structure or improvement or for any part or section of a work may affect, impair or limit the lien of the subcontractor, laborer, or materialman or furnisher of machinery or other necessary material or equipment, as provided in this article, except as otherwise provided in this article.
(b) Notwithstanding any provisions of this code to the contrary, beginning on July 1, 2015, it is an affirmative defense, or an affirmative partial defense, as the case may be, in any action to enforce a lien pursuant to this article that the owner is not indebted to the contractor or is indebted to the contractor for less than the amount of the lien sought to be perfected, when:
(1) The property is an existing single-family dwelling;
(2) The property is a residence constructed by the owner or under a contract entered into by the owner prior to its occupancy as the owner's primary residence; or
(3) The property is a single-family, owner-occupied dwelling, including a residence constructed and sold for occupancy as a primary residence. This subdivision does not apply to a developer or builder of multiple residences except for the residence that is occupied as the primary residence of the developer or builder.