feat: Update activity session metrics handling to skip source field inserts
- Modified the `replace_activity_session_metrics` function to skip EAV inserts for parameters with a defined `source_field`, aligning with the existing logic in `upsert_session_metrics_from_csv_mapped`. - Enhanced the frontend logic to filter out metrics associated with `source_field` during payload construction, improving data integrity and user experience. - Added unit tests to validate the new behavior, ensuring that metrics with `source_field` are correctly excluded from inserts.
This commit is contained in:
1 parent
fd7a2dac6d
commit
94bb4a8199
3 files changed
+104
-2
No files matched your search
@@ -505,6 +505,9 @@ def replace_activity_session_metrics(
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Full replace of EAV rows for this session. metrics: [{ "parameter_key": str, "value": ... }, ...]
|
||||
|
||||
Parameter mit gesetztem ``source_field`` werden nicht in EAV persistiert (kanonisch ``activity_log``),
|
||||
konsistent zu ``upsert_session_metrics_from_csv_mapped`` — verhindert doppelte Speicherung nach PUT.
|
||||
"""
|
||||
cur.execute(
|
||||
"""
|
||||
@@ -535,6 +538,9 @@ def replace_activity_session_metrics(
|
||||
if not s["required"]:
|
||||
continue
|
||||
itk = s["key"]
|
||||
sf_req = s.get("source_field")
|
||||
if sf_req is not None and str(sf_req).strip():
|
||||
continue
|
||||
hit = payload_by_key.get(itk)
|
||||
if hit is None or hit.get("value") is None:
|
||||
raise ActivitySessionMetricsError(400, f"Pflichtfeld fehlt: {itk}")
|
||||
@@ -547,6 +553,9 @@ def replace_activity_session_metrics(
|
||||
for item in metrics:
|
||||
k = str(item["parameter_key"]).strip()
|
||||
spec = by_key[k]
|
||||
sf_raw = spec.get("source_field")
|
||||
if sf_raw is not None and str(sf_raw).strip():
|
||||
continue
|
||||
val = item.get("value")
|
||||
if val is None:
|
||||
if spec["required"]:
|
||||
|
||||
Reference in new issue
Block a user