{"record":{"id":"0606c046e64aa0ff","repo":"dbt-labs/dbt-core","slug":"versions-should-not-be-empty","errorCode":null,"errorMessage":"Versions should not be empty","messagePattern":"Versions should not be empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-parser/src/resolve/resolve_properties.rs","lineNumber":840,"sourceCode":"            .clone()\n            .map(|v| match v {\n                FloatOrString::String(s) => s,\n                FloatOrString::Number(n) => n.to_string(),\n            })\n            .unwrap_or_else(|| {\n                // Try parsing as numbers first\n                let numeric_versions: Vec<_> = version_entries\n                    .iter()\n                    .filter_map(|(v, _, _)| v.parse::<f32>().ok())\n                    .collect();\n\n                if numeric_versions.len() == version_entries.len() {\n                    // If all versions are numeric, use highest number\n                    numeric_versions\n                        .iter()\n                        .reduce(|a, b| if a > b { a } else { b })\n                        .map(|n| n.to_string())\n                        .expect(\"Versions should not be empty\")\n                } else {\n                    // Otherwise use lexicographically last\n                    version_entries\n                        .iter()\n                        .map(|(v, _, _)| v)\n                        .max()\n                        .unwrap()\n                        .clone()\n                }\n            });\n\n        // Find the config for the latest version from existing version entries\n        let latest_version_config = version_entries\n            .iter()\n            .find(|(v, _, _)| v == &latest_version)\n            .map(|(_, _, config)| config.clone())\n            .unwrap_or_else(|| Verbatim::from(None));\n","sourceCodeStart":822,"sourceCodeEnd":858,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-parser/src/resolve/resolve_properties.rs#L822-L858","documentation":"Panic \"Versions should not be empty\" fires in collect_model_version_info when computing the latest version: the `reduce` on numeric_versions (or the fallback max over version_entries) yields None because the collection is empty despite earlier logic implying at least one entry. It selects the highest numeric version string for a versioned model.","triggerScenarios":"A model defines versions where numeric_versions and version_entries end up empty after filtering — e.g., all version entries were filtered out earlier, or `defined_in`/v-defs produced entries that were pruned before this point.","commonSituations":"YAML with a `versions:` block whose entries are all invalid/non-numeric in an unexpected way; upstream dedup removing every version entry; version parsing changes making numeric_versions.len() == 0 while version_entries also empty.","solutions":["Guard the empty case: return an error naming the model when version_entries is empty before reducing.","Verify the earlier branch condition — if numeric_versions.len() == version_entries.len() and both are 0, reduce panics; require len() > 0 in the condition.","Check that the versions YAML block parsed into at least one entry."],"exampleFix":"// before\nif numeric_versions.len() == version_entries.len() {\n    numeric_versions.iter().reduce(...).expect(\"Versions should not be empty\")\n// after\nif !numeric_versions.is_empty() && numeric_versions.len() == version_entries.len() {\n    numeric_versions.iter().reduce(...).expect(\"Versions should not be empty\")","handlingStrategy":"validation","validationCode":"// in YAML: ensure at least one version entry exists\nversions:\n  - v: 1\n  - v: 2","typeGuard":"fn has_versions(entries: &[VersionEntry]) -> bool { !entries.is_empty() }","tryCatchPattern":null,"preventionTips":["Check emptiness explicitly before reduce/max on collections","Ensure version filtering upstream never empties the list silently","Return a named model error instead of panicking in resolvers"],"tags":["rust","versions","panic","empty-collection"],"backgroundTag":"empty-required-field","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}