Menu
Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
1
Share

UUIDRField

Resource field for storing UUID (Universally Unique Identifier) values.

UUIDRField is a specialized StrRField that automatically generates a unique UUID as the default value. Each Resource instance gets its own unique identifier.

This is useful for: - Unique identifiers for resources - Tracking and correlation IDs - External system references - Ensuring uniqueness across distributed systems

Storage behavior: - Stored in KV_STORE by default (inherited from StrRField) - Included in dict views by default - Automatically generates a new UUID if no value is set - UUID format: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Example: ```python class MyResource(Resource): # Automatically gets a unique UUID tracking_id = UUIDRField()

    # Stored in DATABASE for searchability
    external_id = UUIDRField(storage=RFieldStorage.DATABASE)

    # Not included in dict view
    internal_uuid = UUIDRField(include_in_dict_view=False)

# Usage
resource = MyResource()
print(resource.tracking_id)  # e.g., "550e8400-e29b-41d4-a716-446655440000"
```

Note: - A new UUID is generated for each Resource instance - UUIDs are version 4 (random) by default - Cannot specify a default_value (always uses uuid.uuid4())

Attributes
include_in_dict_view: boolstorage: RFieldStoragevalidator: Validator
Functions
__init__

Initialize a UUIDRField that automatically generates unique identifiers.

Note: Unlike other fields, UUIDRField does not accept a default_value parameter as it always generates a new UUID for each instance.

include_in_dict_view : bool - True
If True, included in dict/JSON representations. Defaults to True
storage : RFieldStorage - RFieldStorage.KV_STORE
Storage backend (DATABASE for searchable, KV_STORE for simple storage, NONE for transient). Defaults to KV_STORE
deserialize

Deserialize and validate a value from storage.

Validates the stored value using the field's validator before returning it.

r_field_value : Any
The raw value from storage
Return type : Any
get_default_value

Generate a new UUID v4 as the default value.

This method is called each time a new Resource instance is created, ensuring that each instance gets a unique identifier.

Return type : Any
serialize

Serialize and validate a value for storage.

Validates the value using the field's validator before storing it.

r_field_value : Any
The runtime value to serialize
Return type : Any
Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.