fix: convert SQLAlchemy model objects to dictionaries for JSON serialization
Some checks failed
Cross-Node Transaction Testing / transaction-test (push) Successful in 3s
Deploy to Testnet / deploy-testnet (push) Successful in 1m9s
Integration Tests / test-service-integration (push) Successful in 2m38s
Multi-Node Stress Testing / stress-test (push) Successful in 2s
Node Failover Simulation / failover-test (push) Successful in 2s
Python Tests / test-python (push) Failing after 1m6s
Security Scanning / security-scan (push) Successful in 30s

- Update list_offers to return dict instead of SQLAlchemy model objects
- Fixes ValueError and TypeError in FastAPI jsonable_encoder
- Converts all offer fields to dictionaries with proper datetime serialization
- Added logging for conversion tracking
This commit is contained in:
aitbc
2026-05-08 19:30:42 +02:00
parent 528c822f09
commit 4ac23bf3cf
2 changed files with 48 additions and 4 deletions

View File

@@ -22,7 +22,7 @@ class MarketplaceService:
status: str | None = None,
region: str | None = None,
gpu_model: str | None = None,
) -> list[MarketplaceOffer]:
) -> list[dict]:
"""List marketplace offers"""
try:
logger.info(f"list_offers called with filters: status={status}, region={region}, gpu_model={gpu_model}")
@@ -36,7 +36,29 @@ class MarketplaceService:
logger.info("Executing database query for offers")
result = list((await self.session.execute(stmt)).all())
logger.info(f"Retrieved {len(result)} offers")
return result
# Convert SQLAlchemy model objects to dictionaries for JSON serialization
offers_list = []
for row in result:
offer = row[0] if row else None
if offer:
offers_list.append({
'id': offer.id,
'provider': offer.provider,
'capacity': offer.capacity,
'price': offer.price,
'sla': offer.sla,
'status': offer.status,
'created_at': offer.created_at.isoformat() if offer.created_at else None,
'attributes': offer.attributes,
'gpu_model': offer.gpu_model,
'gpu_memory_gb': offer.gpu_memory_gb,
'gpu_count': offer.gpu_count,
'cuda_version': offer.cuda_version,
'price_per_hour': offer.price_per_hour,
'region': offer.region,
})
logger.info(f"Converted {len(offers_list)} offers to dictionaries")
return offers_list
except Exception as e:
logger.error(f"Error in list_offers: {type(e).__name__}: {str(e)}")
raise

View File

@@ -22,7 +22,7 @@ class MarketplaceService:
status: str | None = None,
region: str | None = None,
gpu_model: str | None = None,
) -> list[MarketplaceOffer]:
) -> list[dict]:
"""List marketplace offers"""
try:
logger.info(f"list_offers called with filters: status={status}, region={region}, gpu_model={gpu_model}")
@@ -36,7 +36,29 @@ class MarketplaceService:
logger.info("Executing database query for offers")
result = list((await self.session.execute(stmt)).all())
logger.info(f"Retrieved {len(result)} offers")
return result
# Convert SQLAlchemy model objects to dictionaries for JSON serialization
offers_list = []
for row in result:
offer = row[0] if row else None
if offer:
offers_list.append({
'id': offer.id,
'provider': offer.provider,
'capacity': offer.capacity,
'price': offer.price,
'sla': offer.sla,
'status': offer.status,
'created_at': offer.created_at.isoformat() if offer.created_at else None,
'attributes': offer.attributes,
'gpu_model': offer.gpu_model,
'gpu_memory_gb': offer.gpu_memory_gb,
'gpu_count': offer.gpu_count,
'cuda_version': offer.cuda_version,
'price_per_hour': offer.price_per_hour,
'region': offer.region,
})
logger.info(f"Converted {len(offers_list)} offers to dictionaries")
return offers_list
except Exception as e:
logger.error(f"Error in list_offers: {type(e).__name__}: {str(e)}")
raise