Failure of Doob-Dynkin lemma in general measurable spaces
The version of the Doob-Dynkin lemma given in my textbook is as follows:
Let $f: \Omega_1 \to \Omega_2$ be a function, let $\mathcal{F}$ be a $\sigma$-algebra on $\Omega_2$, and let $\sigma(f)$ be the $\sigma$-algebra on $\Omega_1$ generated by $f$. Denote the Borel $\sigma$-algebra on $\mathbb{R}$ by $B(\mathbb{R})$. Then, $h : (\Omega_1, \sigma(f)) \to (\mathbb{R}, B(\mathbb{R})) $ is measurable if and only if $h = g \circ f$ for some measurable function $g: (\Omega_2, \mathcal{F}) \to (\mathbb{R}, B(\mathbb{R})) $.
My textbook also states that this lemma fails if we replace $(\mathbb{R},B(\mathbb{R}))$ by some other measurable space, but does not provide an example of this failure. As such, I'm trying to come up with such an example on my own, but am not sure where to begin. Any help is appreciated!
As the composition of measurable functions remains measurable, one direction always holds. So what must fail is the other direction.
Now let $\Omega_1 = \{\omega_1, \omega_2\}$ and consider $f : \Omega_1 \to \Omega_2$ with $\Omega_2 = \{1,2\}$ and $f(\omega_1) = f(\omega_2) = 1$. We take $\mathcal F = \{\emptyset, \Omega_2\}$ as our $\sigma$-algebra, then $\sigma(f) = \{ f^{-1}(\emptyset), f^{-1}(\Omega_2) \} = \{\emptyset, \Omega_1\}$. Also take $\{\emptyset, \mathbb R\}$ as the $\sigma$-algebra on $\mathbb R$ (note that intuitively it is too coarse to "distinguish" the values a measurable function takes), then any function $h : \Omega_1 \to \mathbb R$ is measurable with respect to $\sigma(f)$ on $\Omega_1$ and the $\sigma$-algebra $\{\emptyset, \mathbb R\}$ on $\mathbb R$. But for example for $h(\omega_1) \ne h(\omega_2)$ there is no function $g : \Omega_2 \to \mathbb R$ with $h = g\circ f$, as $g(f(\omega_1)) = g(f(\omega_2))$.
The statement remains true if $\mathbb{R}$ is replaced with a separable, complete metric space. See Kallenberg's book, Lemma 1.13.