|
20 | 20 |
|
21 | 21 | {% macro process_freshness_result(result) %} |
22 | 22 | {% set result_dict = result.to_dict() %} |
23 | | - |
24 | 23 | {# |
25 | | - dbt-core nests the source identifiers under `node` (a full source node), |
26 | | - while dbt-fusion returns a flat result that mirrors `sources.json`: `node` |
27 | | - is none and `unique_id` / `criteria` live at the top level. Resolve from |
28 | | - whichever is populated so both engines upload complete results. |
| 24 | + dbt-fusion returns a none `node` for some freshness results (e.g. errored |
| 25 | + sources), unlike dbt-core. Skip them so the on_run_end hook does not crash |
| 26 | + on `result_dict.node.unique_id`. |
29 | 27 | #} |
30 | | - {% set node = result_dict.get("node") %} |
31 | | - {% set has_node = node is not none and node is not undefined %} |
32 | | - {% set unique_id = ( |
33 | | - node.get("unique_id") if has_node else result_dict.get("unique_id") |
34 | | - ) %} |
35 | | - |
36 | | - {% if unique_id is none %} |
37 | | - {# Nothing identifiable to record (e.g. fusion error result with no node). #} |
38 | | - {% do return(none) %} |
39 | | - {% endif %} |
40 | | - |
41 | | - {% if result_dict.get("status") == "runtime error" %} |
| 28 | + {% if result_dict.get("node") is none %} {% do return(none) %} {% endif %} |
| 29 | + {% if result_dict.status == "runtime error" %} |
42 | 30 | {% do return( |
43 | 31 | { |
44 | | - "unique_id": unique_id, |
45 | | - "status": result_dict.get("status"), |
46 | | - "error": result_dict.get("message") or result_dict.get("error"), |
| 32 | + "unique_id": result_dict.node.unique_id, |
| 33 | + "status": result_dict.status, |
| 34 | + "error": result_dict.message, |
47 | 35 | } |
48 | 36 | ) %} |
49 | 37 | {% endif %} |
50 | | - |
51 | | - {% set criteria = ( |
52 | | - node.get("freshness", {}) if has_node else result_dict.get("criteria", {}) |
53 | | - ) %} |
54 | 38 | {% do return( |
55 | 39 | { |
56 | | - "unique_id": unique_id, |
57 | | - "status": result_dict.get("status"), |
58 | | - "max_loaded_at": result_dict.get("max_loaded_at"), |
59 | | - "snapshotted_at": result_dict.get("snapshotted_at"), |
60 | | - "max_loaded_at_time_ago_in_s": result_dict.get("age") |
61 | | - if result_dict.get("age") is not none |
62 | | - else result_dict.get("max_loaded_at_time_ago_in_s"), |
63 | | - "criteria": criteria or {}, |
64 | | - "adapter_response": result_dict.get("adapter_response"), |
65 | | - "timing": result_dict.get("timing"), |
66 | | - "thread_id": result_dict.get("thread_id"), |
67 | | - "execution_time": result_dict.get("execution_time"), |
| 40 | + "unique_id": result_dict.node.unique_id, |
| 41 | + "status": result_dict.status, |
| 42 | + "max_loaded_at": result_dict.max_loaded_at, |
| 43 | + "snapshotted_at": result_dict.snapshotted_at, |
| 44 | + "max_loaded_at_time_ago_in_s": result_dict.age, |
| 45 | + "criteria": result_dict.node.get("freshness", {}), |
| 46 | + "adapter_response": result_dict.adapter_response, |
| 47 | + "timing": result_dict.timing, |
| 48 | + "thread_id": result_dict.thread_id, |
| 49 | + "execution_time": result_dict.execution_time, |
68 | 50 | } |
69 | 51 | ) %} |
70 | 52 | {% endmacro %} |
|
0 commit comments