Unfortunately its expected behavior, though a bit confusing in this context. The problem comes down to the time when you did the patch.
Consider this:
@dataclass
class Foo:
id: UUID = field(default_factory=uuid4)
The issue is that when that class (not an instance of it) is created, it will take the reference to uuid4 and save it as the default_factory. This action happens at import time, before your patch would evaluate.
A way around this is to do something like this:
@dataclass
class Foo:
id: UUID = field(default_factory=lambda: uuid4())
This works and passes the test case because the reference to the lambda is saved, but the uuid4 function is not evaluated until when the default_factory is called during instance creation… which happens to be after the patch occurs.