Apologies if this question is trivial or has been answered before.
If we consider a Yang-Mills theory (with a simple, compact Lie group $G$) on $\mathbb{R}^4$, it is well-known that all the finite-action gauge connections can be classified by the second Chern number $n$ (see this, for example) given by $$ n = \frac{1}{8\pi^2} \int_{S^4} \text{Tr} \left( F \wedge F\right).$$
The reason why we integrate over $S^4$ is that the boundary condition imposed by finite-action requirement makes it equivalent to consider principal $G$-bundles over $S^4$ instead, and it is possible to construct non-trivial principal bundles on $S^4$. However, this does not mean that we have suddenly changed our base manifold to $S^4$, just that the compactification to $S^4$ aids our classification. This brings me to my question:
Ultimately we are still living in $\mathbb{R}^4$, and any principal bundles we can construct over it is necessarily trivial and the second Chern number vanishes. Does this not mean that the so-called $\theta$ term $$ \frac{\theta}{8\pi^2} \int_{\mathbb{R}^4} \text{Tr} \left( F \wedge F\right)$$ equals 0? And if that is the case, this $\theta$ parameter would become unphysical, in contrary to basically what every paper about the $\theta$ term says.
What am I missing?