diff --git a/dumux/assembly/fvlocalassemblerbase.hh b/dumux/assembly/fvlocalassemblerbase.hh
index 7d894ca276fce2b65e621189b2ad167908ed3bbd..5b77bb610671ad2d7cdb5be6e00f448e8b68fb81 100644
--- a/dumux/assembly/fvlocalassemblerbase.hh
+++ b/dumux/assembly/fvlocalassemblerbase.hh
@@ -221,12 +221,14 @@ public:
         // and set the residual to (privar - dirichletvalue)
         for (const auto& scvI : scvs(this->fvGeometry()))
         {
-            if (this->problem().hasInternalDirichletConstraint(this->element(), scvI))
+            const auto internalDirichletConstraints = this->problem().hasInternalDirichletConstraint(this->element(), scvI);
+            if (internalDirichletConstraints.any())
             {
                 const auto dirichletValues = this->problem().internalDirichlet(this->element(), scvI);
                 // set the Dirichlet conditions in residual and jacobian
-                for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
-                    applyDirichlet(scvI, dirichletValues, eqIdx, eqIdx);
+                for (int eqIdx = 0; eqIdx < internalDirichletConstraints.size(); ++eqIdx)
+                    if (internalDirichletConstraints[eqIdx])
+                        applyDirichlet(scvI, dirichletValues, eqIdx, eqIdx);
             }
         }
     }