Fix no_autoflush: use manual toggle for async session
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m9s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m9s
AsyncSession.no_autoflush is a sync context manager, can't use with 'async with'. Toggle autoflush manually instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -185,9 +185,11 @@ async def _upsert_post(sess: AsyncSession, gp: Dict[str, Any], author_map: Dict[
|
|||||||
obj.user_id = user_id
|
obj.user_id = user_id
|
||||||
await sess.flush()
|
await sess.flush()
|
||||||
|
|
||||||
# Rebuild post_authors + post_tags inside no_autoflush to prevent
|
# Rebuild post_authors + post_tags with synchronize_session to keep
|
||||||
# premature INSERT from query-invoked autoflush.
|
# identity map consistent and prevent autoflush IntegrityError.
|
||||||
async with sess.no_autoflush:
|
old_autoflush = sess.autoflush
|
||||||
|
sess.autoflush = False
|
||||||
|
try:
|
||||||
# Delete + re-add post_authors (dedup for Ghost duplicate authors)
|
# Delete + re-add post_authors (dedup for Ghost duplicate authors)
|
||||||
await sess.execute(
|
await sess.execute(
|
||||||
delete(PostAuthor).where(PostAuthor.post_id == obj.id),
|
delete(PostAuthor).where(PostAuthor.post_id == obj.id),
|
||||||
@@ -212,7 +214,9 @@ async def _upsert_post(sess: AsyncSession, gp: Dict[str, Any], author_map: Dict[
|
|||||||
seen_tags.add(tt.id)
|
seen_tags.add(tt.id)
|
||||||
sess.add(PostTag(post_id=obj.id, tag_id=tt.id, sort_order=idx))
|
sess.add(PostTag(post_id=obj.id, tag_id=tt.id, sort_order=idx))
|
||||||
|
|
||||||
await sess.flush()
|
await sess.flush()
|
||||||
|
finally:
|
||||||
|
sess.autoflush = old_autoflush
|
||||||
|
|
||||||
# Auto-create PageConfig for pages
|
# Auto-create PageConfig for pages
|
||||||
if obj.is_page:
|
if obj.is_page:
|
||||||
|
|||||||
Reference in New Issue
Block a user