fix: add active check post account platform update to prevent silent ignore by remote backend
This commit is contained in:
@@ -1825,6 +1825,16 @@ def organize_website_groups(
|
|||||||
if "group_ids" in update_payload:
|
if "group_ids" in update_payload:
|
||||||
remote_acc["group_ids"] = new_group_ids
|
remote_acc["group_ids"] = new_group_ids
|
||||||
if "platform" in update_payload:
|
if "platform" in update_payload:
|
||||||
|
# 主动核对防线:防止子站忽略 platform 修改而发生静默失败
|
||||||
|
fresh_accs = c.list_accounts() or []
|
||||||
|
fresh_acc = next((a for a in fresh_accs if str(c.extract_id(a)) == str(old_account_id)), None)
|
||||||
|
if fresh_acc:
|
||||||
|
remote_account_map[str(old_account_id)] = fresh_acc
|
||||||
|
new_platform = fresh_acc.get("platform")
|
||||||
|
if str(new_platform).lower() != str(platform).lower():
|
||||||
|
raise WebsiteError(
|
||||||
|
f"远端账号不支持修改平台属性,尝试将平台从 {remote_platform} 修改为 {platform} 失败"
|
||||||
|
)
|
||||||
remote_acc["platform"] = platform
|
remote_acc["platform"] = platform
|
||||||
|
|
||||||
msg_parts = []
|
msg_parts = []
|
||||||
|
|||||||
@@ -541,6 +541,7 @@ def test_organize_groups_corrects_mismatched_platform_instead_of_recreating(db_s
|
|||||||
|
|
||||||
updated_accounts = []
|
updated_accounts = []
|
||||||
create_called = False
|
create_called = False
|
||||||
|
mock_platform = "openai"
|
||||||
|
|
||||||
class MockClient:
|
class MockClient:
|
||||||
def __init__(self, **kwargs): pass
|
def __init__(self, **kwargs): pass
|
||||||
@@ -554,7 +555,7 @@ def test_organize_groups_corrects_mismatched_platform_instead_of_recreating(db_s
|
|||||||
"id": "ACC-G1",
|
"id": "ACC-G1",
|
||||||
"name": "SmartUp-G1",
|
"name": "SmartUp-G1",
|
||||||
"group_ids": ["TG1"],
|
"group_ids": ["TG1"],
|
||||||
"platform": "openai",
|
"platform": mock_platform,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
def extract_id(self, val):
|
def extract_id(self, val):
|
||||||
@@ -564,7 +565,10 @@ def test_organize_groups_corrects_mismatched_platform_instead_of_recreating(db_s
|
|||||||
create_called = True
|
create_called = True
|
||||||
return {"id": "NEW-ACC", "name": body["name"], "group_ids": body["group_ids"]}
|
return {"id": "NEW-ACC", "name": body["name"], "group_ids": body["group_ids"]}
|
||||||
def update_account(self, account_id, body):
|
def update_account(self, account_id, body):
|
||||||
|
nonlocal mock_platform
|
||||||
updated_accounts.append((account_id, body))
|
updated_accounts.append((account_id, body))
|
||||||
|
if "platform" in body:
|
||||||
|
mock_platform = body["platform"]
|
||||||
return {"id": account_id, "platform": body.get("platform")}
|
return {"id": account_id, "platform": body.get("platform")}
|
||||||
|
|
||||||
monkeypatch.setattr("app.routers.websites.Sub2ApiWebsiteClient", MockClient)
|
monkeypatch.setattr("app.routers.websites.Sub2ApiWebsiteClient", MockClient)
|
||||||
|
|||||||
Reference in New Issue
Block a user