Fix cross-DB queries: move page_configs to cart, fix OAuth code_hash lookup
page_configs table lives in db_cart but blog was querying it directly, causing UndefinedTableError. Move all PageConfig read/write endpoints to cart service and have blog proxy via fetch_data/call_action. Also fix OAuth callback to use code_hash lookup (codes are now stored hashed) and pass grant_token in redirect URL to prevent auth loops. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,6 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import selectinload, joinedload
|
||||
|
||||
from models.ghost_content import Post, Author, Tag, PostTag
|
||||
from shared.models.page_config import PageConfig
|
||||
from models.tag_group import TagGroup, TagGroupTag
|
||||
|
||||
|
||||
@@ -280,7 +279,6 @@ class DBClient:
|
||||
joinedload(Post.primary_tag),
|
||||
selectinload(Post.authors),
|
||||
selectinload(Post.tags),
|
||||
joinedload(Post.page_config),
|
||||
)
|
||||
.limit(limit)
|
||||
.offset(offset_val)
|
||||
@@ -288,10 +286,24 @@ class DBClient:
|
||||
|
||||
rows: List[Post] = list((await self.sess.execute(q)).scalars())
|
||||
|
||||
# Load PageConfigs from cart service (page_configs lives in db_cart)
|
||||
post_ids = [p.id for p in rows]
|
||||
pc_map: Dict[int, dict] = {}
|
||||
if post_ids:
|
||||
from shared.infrastructure.data_client import fetch_data
|
||||
try:
|
||||
raw_pcs = await fetch_data("cart", "page-configs-batch",
|
||||
params={"container_type": "page", "ids": ",".join(str(i) for i in post_ids)})
|
||||
if isinstance(raw_pcs, list):
|
||||
for pc in raw_pcs:
|
||||
pc_map[pc["container_id"]] = pc
|
||||
except Exception:
|
||||
pass # graceful degradation — pages render without features
|
||||
|
||||
def _page_to_public(p: Post) -> Dict[str, Any]:
|
||||
d = _post_to_public(p)
|
||||
pc = p.page_config
|
||||
d["features"] = pc.features if pc else {}
|
||||
pc = pc_map.get(p.id)
|
||||
d["features"] = pc["features"] if pc else {}
|
||||
return d
|
||||
|
||||
pages_list = [_page_to_public(p) for p in rows]
|
||||
|
||||
Reference in New Issue
Block a user