From 297c0d798d3847d3077e8eefb85d6fdc2bfded52 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 1 Sep 2026 19:33:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(site):=20=E4=BF=AE=E5=A4=8D=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E6=96=B0=E5=A2=9E=E7=AB=99=E7=82=B9=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=20(#6531)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/application/site/mutation.py | 1 + tests/test_site_mutation_command.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/application/site/mutation.py b/app/application/site/mutation.py index d153f56d9..66fc82e25 100644 --- a/app/application/site/mutation.py +++ b/app/application/site/mutation.py @@ -149,6 +149,7 @@ class SiteMutationCommand: if await self._repository.async_get_by_domain(domain): return SiteMutationResult(False, f"{domain} 站点己存在") + values.pop("id", None) values.update( { "domain": domain, diff --git a/tests/test_site_mutation_command.py b/tests/test_site_mutation_command.py index cd25925b1..be4d77b29 100644 --- a/tests/test_site_mutation_command.py +++ b/tests/test_site_mutation_command.py @@ -4,6 +4,7 @@ import pytest from app.application.site.contract import SiteMutation, SitePriorityMutation from app.application.site.mutation import SiteMutationCommand +from app.schemas.site import Site def _command(**overrides): @@ -56,6 +57,20 @@ async def test_create_site_commits_before_updated_event(): assert mutation.values["public"] == 1 +@pytest.mark.asyncio +async def test_create_site_ignores_schema_identity_field(): + """手动新增站点应忽略请求 Schema 自动补出的空主键。""" + command, dependencies = _command() + + result = await command.create( + Site(url="https://demo.example/path").model_dump() + ) + + assert result.success is True + mutation = dependencies["repository"].stage_create.await_args.args[0] + assert "id" not in mutation.values + + @pytest.mark.asyncio async def test_update_site_returns_legacy_not_found_without_writes(): """更新不存在站点时保持失败响应且不产生事务或事件。"""