dbt-labs/dbt-core · error
ok
Error message
ok
What it means
A test panic from `expect("ok")` on `<Vec<ViewDefinition>>::from_recording_json(&json)`. The recording codec must reconstruct a Vec<ViewDefinition> from its `to_recording_json` output; any deserialize error (missing fields, non-serializable AdapterType dialect, field drift) panics the test. It means the ViewDefinition recording format is not round-trip safe at `crates/dbt-adapter/src/time_machine/metadata.rs:918`.
Source
Thrown at crates/dbt-adapter/src/time_machine/metadata.rs:918
let args = args_fetch_view_definitions(["a.b.c", "d.e.f"]);
assert!(matches!(
args,
MetadataCallArgs::FetchViewDefinitions { relations } if relations == vec!["a.b.c", "d.e.f"]
));
}
#[test]
fn test_view_definition_vec_round_trips_via_recording_json() {
use crate::metadata::ViewDefinition;
let original = vec![ViewDefinition {
fqn: r#""DB"."S"."V""#.to_string(),
definition: "SELECT 1".to_string(),
dialect: AdapterType::Snowflake,
default_catalog: "DB".to_string(),
default_schema: "S".to_string(),
}];
let json = original.to_recording_json();
let restored = <Vec<ViewDefinition>>::from_recording_json(&json).expect("ok");
assert_eq!(restored.len(), 1);
assert_eq!(restored[0].fqn, original[0].fqn);
assert_eq!(restored[0].definition, original[0].definition);
assert_eq!(restored[0].dialect, original[0].dialect);
assert_eq!(restored[0].default_catalog, original[0].default_catalog);
assert_eq!(restored[0].default_schema, original[0].default_schema);
}
#[test]
fn test_view_definition_fetch_result_round_trips_unresolvable() {
use crate::metadata::{ViewDefinition, ViewDefinitionFetchResult};
let original = ViewDefinitionFetchResult {
definitions: vec![ViewDefinition {
fqn: r#""DB"."S"."V""#.to_string(),
definition: "SELECT 1".to_string(),
dialect: AdapterType::Snowflake,
default_catalog: "DB".to_string(),
default_schema: "S".to_string(),View on GitHub (pinned to 0267ce9170)
Solutions
- Inspect the underlying error by replacing expect with unwrap_or_else that prints the error and the json payload.
- Verify every field of ViewDefinition is serialized by to_recording_json and read back by from_recording_json (fqn, definition, dialect, default_catalog, default_schema).
- Update the ViewDefinition recording impl after any struct field change, and regenerate old recordings.
- Add serde round-trip property tests so drift is caught at compile/CI time.
Example fix
// before
let restored = <Vec<ViewDefinition>>::from_recording_json(&json).expect("ok");
// after
let restored = <Vec<ViewDefinition>>::from_recording_json(&json)
.unwrap_or_else(|e| panic!("view definitions failed to deserialize: {e}; json={json}")); Defensive patterns
Strategy: validation
Validate before calling
fn view_definitions_roundtrip(v: &[ViewDefinition]) -> bool {
v.to_recording_json()
.and_then(|j| <Vec<ViewDefinition>>::from_recording_json(&j))
.map(|r| r.len() == v.len())
.unwrap_or(false)
} Type guard
fn is_valid_recording_json(j: &serde_json::Value) -> bool {
j.is_object() && j.get("definitions").map_or(false, |d| d.is_array())
} Try / catch
match <Vec<ViewDefinition>>::from_recording_json(&json) {
Ok(v) => v,
Err(e) => { log::warn("view definition replay decode failed: {e}"); Vec::new() }
} Prevention
- Keep ViewDefinition fields in sync with its recording JSON impl after any struct edit.
- Pin AdapterType serde representation in replay tests.
- Version recordings and reject mismatches early.
When it happens
Trigger: `Vec<ViewDefinition>::from_recording_json` receiving JSON from `to_recording_json` where a ViewDefinition field (fqn, definition, dialect, default_catalog, default_schema) is missing, renamed, or of unexpected type.
Common situations: Adding or renaming a field on ViewDefinition without updating its recording JSON impl; AdapterType serde representation changing; replaying old recordings against a newer struct definition.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- Failed to deserialize
- invalid serialized time precision
- invalid serialized timestamp precision
- RelationConfig should serialize
- original value should be serializable via the time-machine r
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/70b7026c6423d453.
Report an issue: GitHub.