  Let $\Omega\subset\mathbb{C}$ be a bounded domain such that there exists an
algebraic harmonic function of degree two vanishing on the boundary of
$\Omega.$ Then we show that the Khavinson-Shapiro conjecture holds for
$\Omega:$ if the Dirichlet problem on $\Omega$ with all polynomial boundary
data have polynomial solutions, then $\Omega$ must be an ellipse. We also prove
that if there exists a rational function with a singularity in $\Omega$, such
that the Dirichlet problem for its restriction on $\partial\Omega$ along with
all polynomial functions have rational solutions, then $\Omega$ must be a disc.
This generalizes a well-known result by Bell, Ebenfelt, Khavinson, and Shapiro.
Our proofs are purely algebraic.
