Skip to content

Instantly share code, notes, and snippets.

@solebox
Created August 8, 2024 12:55
Show Gist options
  • Save solebox/7c344ebf7faf739560a7fbdf01384b9e to your computer and use it in GitHub Desktop.
Save solebox/7c344ebf7faf739560a7fbdf01384b9e to your computer and use it in GitHub Desktop.
faust Field for uuid
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