From fca0950cd10d5e972fb810fa49e0f1e9c0cc7a43 Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 14 Feb 2026 09:52:13 +0000 Subject: [PATCH] Add attach/detach glue calls to calendar and market CRUD Wire up ContainerRelation tracking via attach_child/detach_child in: - calendars: create (including revive), soft_delete - markets: create (including revive), soft_delete Co-Authored-By: Claude Opus 4.6 --- bp/calendars/services/calendars.py | 4 ++++ bp/markets/services/markets.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/bp/calendars/services/calendars.py b/bp/calendars/services/calendars.py index 445720a..59982c1 100644 --- a/bp/calendars/services/calendars.py +++ b/bp/calendars/services/calendars.py @@ -5,6 +5,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from models.calendars import Calendar from blog.models.ghost_content import Post # for FK existence checks +from glue.services.relationships import attach_child, detach_child import unicodedata import re @@ -66,6 +67,7 @@ async def soft_delete(sess: AsyncSession, post_slug: str, calendar_slug: str) -> cal.deleted_at = utcnow() await sess.flush() + await detach_child(sess, "page", cal.container_id, "calendar", cal.id) return True async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calendar: @@ -98,12 +100,14 @@ async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calend if existing.deleted_at is not None: existing.deleted_at = None # revive await sess.flush() + await attach_child(sess, "page", post_id, "calendar", existing.id) return existing raise CalendarError(f'Calendar with slug "{slug}" already exists for post {post_id}.') cal = Calendar(container_type="page", container_id=post_id, name=name, slug=slug) sess.add(cal) await sess.flush() + await attach_child(sess, "page", post_id, "calendar", cal.id) return cal diff --git a/bp/markets/services/markets.py b/bp/markets/services/markets.py index 76acd4d..785ec04 100644 --- a/bp/markets/services/markets.py +++ b/bp/markets/services/markets.py @@ -9,6 +9,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from market.models.market_place import MarketPlace from blog.models.ghost_content import Post from shared.browser.app.utils import utcnow +from glue.services.relationships import attach_child, detach_child class MarketError(ValueError): @@ -55,12 +56,14 @@ async def create_market(sess: AsyncSession, post_id: int, name: str) -> MarketPl existing.deleted_at = None existing.name = name await sess.flush() + await attach_child(sess, "page", post_id, "market", existing.id) return existing raise MarketError(f'Market with slug "{slug}" already exists for this page.') market = MarketPlace(container_type="page", container_id=post_id, name=name, slug=slug) sess.add(market) await sess.flush() + await attach_child(sess, "page", post_id, "market", market.id) return market @@ -83,4 +86,5 @@ async def soft_delete(sess: AsyncSession, post_slug: str, market_slug: str) -> b market.deleted_at = utcnow() await sess.flush() + await detach_child(sess, "page", market.container_id, "market", market.id) return True