diff_utils
Shared diff utilities for pending queue and audit trail.
This module provides field-level diff computation and related models that are reused across both pending change preview diffs and applied batch net-change analysis.
CRITICAL_FIELDS_BY_CATEGORY
module-attribute
CRITICAL_FIELDS_BY_CATEGORY: dict[
MODEL_REFERENCE_CATEGORY, set[str]
] = {
image_generation: {
"baseline",
"nsfw",
"inpainting",
"trigger",
"homepage",
},
text_generation: {
"baseline",
"nsfw",
"url",
"parameters",
},
controlnet: {"style", "nsfw"},
blip: {"style", "nsfw"},
clip: {"style", "nsfw"},
codeformer: {"style", "nsfw"},
esrgan: {"style", "nsfw"},
gfpgan: {"style", "nsfw"},
safety_checker: {"style", "nsfw"},
}
NetChangeType
Bases: StrEnum
Type of net change for a model across a batch or pending change.
Source code in src/horde_model_reference/pending_queue/diff_utils.py
FieldChangeType
Bases: StrEnum
Type of field-level change.
Source code in src/horde_model_reference/pending_queue/diff_utils.py
FieldDiff
Bases: BaseModel
Field-level difference between before and after states.
Source code in src/horde_model_reference/pending_queue/diff_utils.py
compute_field_diffs
compute_field_diffs(
before: dict[str, Any] | None,
after: dict[str, Any] | None,
*,
prefix: str = "",
recursive: bool = True,
) -> list[FieldDiff]
Compute field-level differences between two states.
Parameters:
-
before(dict[str, Any] | None) –The original/current state (None if model doesn't exist).
-
after(dict[str, Any] | None) –The proposed/new state (None if model is being deleted).
-
prefix(str, default:'') –Path prefix for nested field tracking (used internally).
-
recursive(bool, default:True) –If True, recursively diff nested dicts for granular changes.
Returns:
Source code in src/horde_model_reference/pending_queue/diff_utils.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 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 | |
has_critical_changes
Check if any field diffs involve critical fields for the category.
Parameters:
-
category(MODEL_REFERENCE_CATEGORY) –The model reference category being modified.
-
diffs(list[FieldDiff]) –List of field diffs to check.
Returns:
-
bool–True if any diff involves a critical field, False otherwise.
Source code in src/horde_model_reference/pending_queue/diff_utils.py
categorize_field_diffs
Categorize field diffs by change type.
Parameters:
Returns:
-
tuple[list[str], list[str], list[str]]–Tuple of (fields_added, fields_removed, fields_modified) lists.