fix(problem): resolve_tags 的 create 包一层 atomic

外层若在事务里,IntegrityError 会中止整个事务,导致回查抛
TransactionManagementError。当前未开 ATOMIC_REQUESTS 所以还没触发,
但仓库多处用了 transaction.atomic(),属于随时会踩的坑。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-05 04:29:48 -06:00
parent 5b393a3b4c
commit db104ac091

View File

@@ -1,5 +1,5 @@
from django.core.cache import cache from django.core.cache import cache
from django.db import IntegrityError from django.db import IntegrityError, transaction
from utils.constants import CacheKey from utils.constants import CacheKey
@@ -39,6 +39,9 @@ def resolve_tags(names):
tag = ProblemTag.objects.filter(name__iexact=name).first() tag = ProblemTag.objects.filter(name__iexact=name).first()
if tag is None: if tag is None:
try: try:
# 包一层 atomic外层若在事务里IntegrityError 会中止整个事务,
# 导致下面的回查抛 TransactionManagementError
with transaction.atomic():
tag = ProblemTag.objects.create(name=name) tag = ProblemTag.objects.create(name=name)
created = True created = True
except IntegrityError: except IntegrityError: