utils
Utility functions for backends in the Merlin application.
These utilities are essential for converting in-memory data models into a persistable format, ensuring compatibility with backend storage systems, and for consistent error handling when entity lookups fail.
deserialize_entity(data, model_class)
Given data that was retrieved, convert it into a data_class instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, str]
|
The data retrieved that we need to deserialize. |
required |
model_class
|
T
|
A |
required |
Returns:
| Type | Description |
|---|---|
T
|
A |
Source code in merlin/backends/utils.py
get_not_found_error_class(model_class)
Get the appropriate not found error class based on the model type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_class
|
Type[T]
|
A |
required |
Returns:
| Type | Description |
|---|---|
Exception
|
The error class to use. |
Source code in merlin/backends/utils.py
is_iso_datetime(value)
Check if a string is in ISO 8601 datetime format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The string to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the string is in ISO 8601 format, False otherwise. |
Source code in merlin/backends/utils.py
serialize_entity(entity)
Given a BaseDataModel instance,
convert it's data into a format that the database can interpret.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
T
|
A |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
A dictionary of information that the database can interpret. |