Created
August 8, 2024 12:55
-
-
Save solebox/7c344ebf7faf739560a7fbdf01384b9e to your computer and use it in GitHub Desktop.
faust Field for uuid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from faust.models.fields import FieldDescriptor | |
class UUIDField(FieldDescriptor[UUID]): | |
def prepare_value( | |
self, value: Any, *, coerce: Optional[bool] = None | |
) -> Optional[UUID]: | |
if self.should_coerce(value, coerce): | |
if value is not None and not isinstance(value, UUID): | |
return uuid.UUID(value) | |
else: | |
return value | |
else: | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment