Assemble matrix of a subdomain

keep_diagonal should not fix this issue by it-self, as it only keeps zero-entries in the sparsity pattern (ref: Bitbucket)

You would have to call ident_zeros in legacy DOLFIN to resolve that issue (which would add identity rows in these places).
For this to be done with dolfinx, see for instance:

or