diff --git a/video-gen-api/app/main.py b/video-gen-api/app/main.py index 9a2a5e73..c3ec4c4c 100644 --- a/video-gen-api/app/main.py +++ b/video-gen-api/app/main.py @@ -413,6 +413,12 @@ async def _seed_data(): existing_page = existing.scalar_one_or_none() parent_id = frontend_group_ids.get(group_label) + if parent_id: + parent_exists = await db.execute( + select(MenuConfig).where(MenuConfig.id == parent_id).limit(1) + ) + if not parent_exists.scalar_one_or_none(): + parent_id = None if not parent_id: group_exists = await db.execute( select(MenuConfig).where( @@ -439,7 +445,7 @@ async def _seed_data(): if existing_page.is_default != is_default: existing_page.is_default = is_default needs_update = True - if parent_id and existing_page.parent_id != parent_id: + if existing_page.parent_id != parent_id: existing_page.parent_id = parent_id needs_update = True else: @@ -521,6 +527,12 @@ async def _seed_data(): existing_page = existing.scalar_one_or_none() parent_id = admin_group_ids.get(parent_group) if parent_group else None + if parent_id: + parent_exists = await db.execute( + select(MenuConfig).where(MenuConfig.id == parent_id).limit(1) + ) + if not parent_exists.scalar_one_or_none(): + parent_id = None if not parent_id and parent_group: group_exists = await db.execute( select(MenuConfig).where(