apply
Applies approved pending changes to the live model reference dataset via the backend.
BackendUpdateCallable
Bases: Protocol
Protocol for backend update operations, supporting both legacy and canonical formats.
Source code in src/horde_model_reference/pending_queue/apply.py
__call__
__call__(
category: MODEL_REFERENCE_CATEGORY,
model_name: str,
record_dict: dict[str, Any],
*,
logical_user_id: str | None = None,
request_id: str | None = None,
) -> None
Protocol for backend update operations, supporting both legacy and canonical formats.
The callable should perform the necessary update or create operation for the given category and model name, using the provided record dictionary as the source of truth for the model's fields. The callable must also accept optional parameters for logical user ID and request ID to support auditing and traceability of changes through the pending change application process.
Parameters:
-
category(MODEL_REFERENCE_CATEGORY) –The category of the model being updated (e.g., image generation, text generation, etc.).
-
model_name(str) –The unique name of the model to update.
-
record_dict(dict[str, Any]) –A dictionary representing the model's fields and their new values.
-
logical_user_id(str | None, default:None) –An optional immutable user ID for auditing purposes, representing the user on whose behalf the change is being applied.
-
request_id(str | None, default:None) –An optional identifier for the request or job performing the update (e.g., a batch apply job ID or CLI invocation ID) to support traceability in logs and audits.
Source code in src/horde_model_reference/pending_queue/apply.py
BackendDeleteCallable
Bases: Protocol
Protocol for backend delete operations, supporting both legacy and canonical formats.
Source code in src/horde_model_reference/pending_queue/apply.py
__call__
__call__(
category: MODEL_REFERENCE_CATEGORY,
model_name: str,
*,
logical_user_id: str | None = None,
request_id: str | None = None,
) -> None
Protocol for backend delete operations, supporting both legacy and canonical formats.
The callable should perform the necessary delete operation for the given category and model name. The callable must also accept optional parameters for logical user ID and request ID to support auditing and traceability of changes through the pending change application process.
Parameters:
-
category(MODEL_REFERENCE_CATEGORY) –The category of the model being deleted (e.g., image generation, text generation, etc.).
-
model_name(str) –The unique name of the model to delete.
-
logical_user_id(str | None, default:None) –An optional immutable user ID for auditing purposes, representing the user on whose behalf the change is being applied.
-
request_id(str | None, default:None) –An optional identifier for the request or job performing the delete (e.g., a batch apply job ID or CLI invocation ID) to support traceability in logs and audits.
Source code in src/horde_model_reference/pending_queue/apply.py
PendingChangeApplyError
Bases: RuntimeError
Base class for pending change apply failures.
PendingChangeApplyResult
dataclass
Return value when applying a pending change via helper APIs.
Source code in src/horde_model_reference/pending_queue/apply.py
PendingChangeApplyManyResult
dataclass
Return value when applying multiple pending changes sequentially.
Source code in src/horde_model_reference/pending_queue/apply.py
batch_split_original_batch_id
class-attribute
instance-attribute
batch_split_new_batch_id
class-attribute
instance-attribute
batch_split_reassigned_count
class-attribute
instance-attribute
__init__
__init__(
applied_records: list[PendingChangeRecord],
failed_change_id: int | None = None,
failed_error: PendingChangeApplyError | None = None,
batch_split_occurred: bool = False,
batch_split_original_batch_id: int | None = None,
batch_split_new_batch_id: int | None = None,
batch_split_reassigned_count: int | None = None,
) -> None
PendingChangeNotFoundError
Bases: PendingChangeApplyError
Raised when a requested pending change cannot be found.
PendingChangeStateError
Bases: PendingChangeApplyError
Raised when a pending change is in an invalid state for apply.
PendingChangePayloadError
Bases: PendingChangeApplyError
Raised when a change lacks the payload required for application.
PendingChangeBackendError
Bases: PendingChangeApplyError
Raised when the backend fails to persist the applied change.
apply_pending_change
apply_pending_change(
*,
manager: ModelReferenceManager,
queue_service: PendingQueueService,
change_id: int,
applied_by: str,
applied_username: str,
job_id: str | None = None,
) -> PendingChangeApplyResult
Apply an approved pending change through the write-capable backend.
Parameters:
-
manager(ModelReferenceManager) –Singleton manager exposing the write-capable backend.
-
queue_service(PendingQueueService) –Pending queue service used for persistence updates.
-
change_id(int) –Identifier of the pending change to apply.
-
applied_by(str) –Immutable Horde user id for auditing purposes.
-
applied_username(str) –Username corresponding to
applied_by. -
job_id(str | None, default:None) –Optional identifier for the job or CLI invocation performing the apply.
Returns:
-
PendingChangeApplyResult–PendingChangeApplyResult containing the updated record (now marked as applied).
Raises:
-
PendingChangeNotFoundError–If the change cannot be located.
-
PendingChangeStateError–If the change is not approved yet.
-
PendingChangePayloadError–When the change operation requires a payload but none exists.
-
PendingChangeBackendError–If the backend rejects or fails to persist the write.
Source code in src/horde_model_reference/pending_queue/apply.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
validate_batch_cohesion
validate_batch_cohesion(
*,
change_ids: Sequence[int],
queue_service: PendingQueueService,
) -> None
Validate that all change_ids belong to the same batch.
Parameters:
-
change_ids(Sequence[int]) –List of change IDs to validate
-
queue_service(PendingQueueService) –The active pending queue service
Raises:
-
ValueError–If changes belong to different batches or have no batch_id
-
PendingChangeNotFoundError–If any change_id is not found
Source code in src/horde_model_reference/pending_queue/apply.py
apply_pending_changes
apply_pending_changes(
*,
manager: ModelReferenceManager,
queue_service: PendingQueueService,
change_ids: Sequence[int],
applied_by: str,
applied_username: str,
job_id: str | None = None,
enforce_batch_cohesion: bool = True,
) -> PendingChangeApplyManyResult
Apply multiple approved changes sequentially, stopping on first failure.
Parameters:
-
manager(ModelReferenceManager) –The active model reference manager
-
queue_service(PendingQueueService) –The active pending queue service
-
change_ids(Sequence[int]) –List of change IDs to apply
-
applied_by(str) –The user ID applying the changes
-
applied_username(str) –The username applying the changes
-
job_id(str | None, default:None) –An optional job identifier for tracking the apply job
-
enforce_batch_cohesion(bool, default:True) –If True, all changes must belong to the same batch
Returns:
-
PendingChangeApplyManyResult(PendingChangeApplyManyResult) –Summary of the apply operation, including
-
PendingChangeApplyManyResult–batch split information if a partial apply triggered reassignment.
Raises:
-
ValueError–If enforce_batch_cohesion=True and changes belong to different batches
-
PendingChangeNotFoundError–If any change_id is not found
Source code in src/horde_model_reference/pending_queue/apply.py
_apply_change_to_backend
_apply_change_to_backend(
record: PendingChangeRecord,
*,
backend_update: BackendUpdateCallable,
backend_delete: BackendDeleteCallable,
logical_user_id: str,
request_id: str | None,
) -> None
Execute the backend mutation for the given pending change.