fix(scan): persist results to existing details column, errors to error column

The Scan model exposes details (JSON) and error (Text) columns, but the
enricher/flow tasks assigned to scan.results — a non-mapped attribute.
SQLAlchemy accepted the assignment silently, so commit() never persisted
it and the data was lost. Success paths now write scan.details; failure
paths write scan.error. ScanCreate.results renamed to details to match.

Scan repository tests pass.
This commit is contained in:
dextmorgn
2026-05-30 19:02:14 +02:00
parent ee06d6cf3e
commit 1d409d7929
3 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ class ScanCreate(BaseModel):
values: Optional[List[str]] = None
sketch_id: Optional[UUID4] = None
status: Optional[str] = None
results: Optional[Any] = None
details: Optional[Any] = None
class ScanRead(ORMBase):
@@ -69,10 +69,10 @@ def run_enricher(
results = asyncio.run(enricher.execute(values=serialized_objects))
scan.status = EventLevel.COMPLETED
scan.results = to_json_serializable(results)
scan.details = to_json_serializable(results)
session.commit()
return {"result": scan.results}
return {"result": scan.details}
except Exception as ex:
session.rollback()
@@ -82,7 +82,7 @@ def run_enricher(
scan = session.query(Scan).filter(Scan.id == uuid.UUID(self.request.id)).first()
if scan:
scan.status = EventLevel.FAILED
scan.results = {"error": error_logs}
scan.error = error_logs
session.commit()
self.update_state(state=states.FAILURE)
@@ -145,10 +145,10 @@ def run_template_enricher(
results = asyncio.run(enricher.execute(values=serialized_objects))
scan.status = EventLevel.COMPLETED
scan.results = to_json_serializable(results)
scan.details = to_json_serializable(results)
session.commit()
return {"result": scan.results}
return {"result": scan.details}
except Exception as ex:
session.rollback()
@@ -162,7 +162,7 @@ def run_template_enricher(
)
if scan:
scan.status = EventLevel.FAILED
scan.results = {"error": error_logs}
scan.error = error_logs
session.commit()
self.update_state(state=states.FAILURE)
@@ -65,10 +65,10 @@ def run_flow(
results = enricher.scan(values=serialized_objects)
scan.status = EventLevel.COMPLETED
scan.results = to_json_serializable(results)
scan.details = to_json_serializable(results)
session.commit()
return {"result": scan.results}
return {"result": scan.details}
except Exception as ex:
session.rollback()
@@ -78,7 +78,7 @@ def run_flow(
scan = session.query(Scan).filter(Scan.id == uuid.UUID(self.request.id)).first()
if scan:
scan.status = EventLevel.FAILED
scan.results = {"error": error_logs}
scan.error = error_logs
session.commit()
self.update_state(state=states.FAILURE)