Fix Simple Mapping not applying during sync - preserve id field

Root cause: The UUID (id) field was being stripped when saving path mapping:
- Backend ReplacementRule model was missing id field
- Frontend pathMappingToApi() didn't include id in conversion
- Backend update_path_mapping endpoint didn't save id

Changes:
- Add id field to ReplacementRule model in main.py
- Include id when saving path mapping rules in update_path_mapping
- Include id in frontend pathMappingToApi conversion

Co-authored-by: Koha9 <36852125+Koha9@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-03 13:46:37 +00:00
parent 6a1780bcee
commit 1131b81454
2 changed files with 7 additions and 6 deletions
+6 -5
View File
@@ -93,6 +93,7 @@ class RegexRule(BaseModel):
class ReplacementRule(BaseModel):
id: str = ""
search: str
replace: str = ""
@@ -404,12 +405,12 @@ async def update_regex_rules(payload: RegexRulePayload):
async def update_path_mapping(payload: PathMappingPayload):
path_mapping_dict = {
"mode": payload.mode,
"simple": [{"search": rule.search, "replace": rule.replace} for rule in payload.simple],
"simple": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.simple],
"regex": {
"local_pre": [{"search": rule.search, "replace": rule.replace} for rule in payload.regex.local_pre],
"local_post": [{"search": rule.search, "replace": rule.replace} for rule in payload.regex.local_post],
"remote_pre": [{"search": rule.search, "replace": rule.replace} for rule in payload.regex.remote_pre],
"remote_post": [{"search": rule.search, "replace": rule.replace} for rule in payload.regex.remote_post],
"local_pre": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.regex.local_pre],
"local_post": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.regex.local_post],
"remote_pre": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.regex.remote_pre],
"remote_post": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.regex.remote_post],
}
}
server_config.set_and_save_config(path_mapping=path_mapping_dict)