Schliesse das Notebook-Source-Mapping, damit Wizard und Taxonomie ohne leere Kategorie starten.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b276758ee1
commit
d784248e28
13 files changed
+1505
-9
No files matched your search
@@ -1,11 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from uuid import uuid4
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.discovery.enums import FilterType, MappingStatus
|
||||
from app.discovery.enums import FilterType, MappingStatus, TaxonomyStatus
|
||||
from app.domain.serialize import jsonable
|
||||
from app.errors import AppError
|
||||
from app.persistence.discovery_models import (
|
||||
@@ -61,6 +62,7 @@ class CatalogService:
|
||||
"display_name": sources[row.source_id].name if row.source_id in sources else row.name,
|
||||
"external_category_key": row.external_category_key,
|
||||
"status": row.status,
|
||||
"taxonomy_status": row.taxonomy_status,
|
||||
}
|
||||
for row in rows
|
||||
]
|
||||
@@ -82,6 +84,8 @@ class CatalogService:
|
||||
"name": row.name,
|
||||
"product_category_id": row.product_category_id,
|
||||
"status": row.status,
|
||||
"taxonomy_status": row.taxonomy_status,
|
||||
"source_url": row.source_url,
|
||||
}
|
||||
for row in rows
|
||||
]
|
||||
@@ -96,6 +100,16 @@ class CatalogService:
|
||||
SourceCategoryRecord.product_category_id == product_category_id,
|
||||
)
|
||||
).first()
|
||||
if source_category is not None and source_category.taxonomy_status == TaxonomyStatus.NOT_LEARNED.value:
|
||||
from app.services.discovery_service import TaxonomyService
|
||||
|
||||
TaxonomyService(self.session).discover(source_id, source_category.external_category_key)
|
||||
source_category = self.session.scalars(
|
||||
select(SourceCategoryRecord).where(
|
||||
SourceCategoryRecord.source_id == source_id,
|
||||
SourceCategoryRecord.product_category_id == product_category_id,
|
||||
)
|
||||
).first()
|
||||
criteria: list[dict[str, Any]] = []
|
||||
if source_category is not None:
|
||||
filters = self.session.scalars(
|
||||
@@ -222,3 +236,43 @@ def ensure_product_category(session: Session, category_id: str, name: str | None
|
||||
session.add(row)
|
||||
session.flush()
|
||||
return row
|
||||
|
||||
|
||||
def ensure_source_category(
|
||||
session: Session,
|
||||
*,
|
||||
source_id: str,
|
||||
external_category_key: str,
|
||||
product_category_id: str,
|
||||
name: str,
|
||||
source_url: str,
|
||||
) -> SourceCategoryRecord:
|
||||
row = session.scalars(
|
||||
select(SourceCategoryRecord).where(
|
||||
SourceCategoryRecord.source_id == source_id,
|
||||
SourceCategoryRecord.external_category_key == external_category_key,
|
||||
)
|
||||
).first()
|
||||
if row is None:
|
||||
row = SourceCategoryRecord(
|
||||
id=uuid4(),
|
||||
source_id=source_id,
|
||||
external_category_key=external_category_key,
|
||||
name=name,
|
||||
source_url=source_url,
|
||||
product_category_id=product_category_id,
|
||||
canonical_category=product_category_id,
|
||||
status="ACTIVE",
|
||||
taxonomy_status=TaxonomyStatus.NOT_LEARNED.value,
|
||||
last_taxonomy_scan_at=None,
|
||||
last_verified_at=None,
|
||||
)
|
||||
session.add(row)
|
||||
session.flush()
|
||||
return row
|
||||
if row.product_category_id is None:
|
||||
row.product_category_id = product_category_id
|
||||
if not row.source_url:
|
||||
row.source_url = source_url
|
||||
session.flush()
|
||||
return row
|
||||
Reference in new issue
Block a user