I want to transform from planar $x,y$ coordinates to $r,\theta$ coordinates, where
$$r = \sqrt{x^2+y^2},\quad \theta = \arctan(y/x)$$ $$x = r\cos\theta, \quad y = r\sin\theta.$$
To do this I wish to compute the Jacobian matrix. One first step is computing $\partial r/\partial x$. I find
$$\frac{\partial r}{\partial x} = \left(\frac{\partial x}{\partial r}\right)^{-1} = \left(\frac{\partial{(r \cos\theta)}}{\partial r}\right)^{-1} = \frac{1}{\cos\theta}.$$
However I also find
$$\frac{\partial r}{\partial x} = \frac{\partial}{\partial x} \sqrt{x^2+y^2} = \frac{x}{\sqrt{x^2+y^2}} = \frac{r\cos\theta}{r} = \cos \theta.$$
Why do I get these contradictory results?
As said in the comments you cannot just "reverse" the partial derivative like this.
Instead you can actually calculate $\dfrac{\partial r}{\partial x}$ by considering also derivating $\theta$ respectively to $x$ (while $y$ is fixed).
$\dfrac{\partial \theta}{\partial x}=\dfrac{-y}{x^2\left(1+\dfrac{y^2}{x^2}\right)}=\dfrac{-y}{x^2+y^2}=\dfrac{-\sin \theta}{r}$
$\begin{align}\dfrac{\partial r}{\partial x} &=\dfrac{\partial}{\partial x}\left(\dfrac{x}{\cos \theta}\right) =\dfrac 1{\cos \theta}+x\dfrac{\partial}{\partial \theta}\left(\dfrac 1{\cos \theta}\right)\dfrac{\partial \theta}{\partial x} =\dfrac 1{\cos \theta}+x\left(\dfrac{\sin \theta}{\cos^2 \theta}\right)\left(\dfrac{-\sin \theta}{r}\right)\\\\ &=\dfrac 1{\cos \theta}+x\left(\dfrac{-\sin^2 \theta}{x\cos \theta}\right) =\dfrac{1-\sin^2 \theta}{\cos \theta}=\cos \theta \end{align}$
Now both results agree.
Yet you can notice that you still needed to express $\theta$ in term of $x,y$ to get its proper derivative. Thus what you somehow tried to avoid for $r$ you have to do for $\theta$, so it was preferable to go for your second calculation right away.