diff --git a/crates/sqlbuild-analysis/src/contracts/_helpers/columns.rs b/crates/sqlbuild-analysis/src/contracts/_helpers/columns.rs index c3c6487adc..0f8bcf04c4 100644 --- a/crates/sqlbuild-analysis/src/contracts/_helpers/columns.rs +++ b/crates/sqlbuild-analysis/src/contracts/_helpers/columns.rs @@ -265,9 +265,9 @@ fn missing_column( format!( "add {name} to the SELECT list or correct/remove {declaration_label}; \ {declaration_label} is validated using static SQL analysis because \ - settings.column_contract_mode is \"implicit\" (the default). If this project \ + settings.check_declared_columns is true (the default). If this project \ intentionally uses columns only for metadata and audits, set [settings] \ - column_contract_mode = \"explicit\"; models with contract enforced remain validated" + check_declared_columns = false; models with contract enforced remain validated" ) }; ContractDiagnostic { diff --git a/crates/sqlbuild-analysis/src/contracts/models.rs b/crates/sqlbuild-analysis/src/contracts/models.rs index 727f5e7c12..d6d67a3710 100644 --- a/crates/sqlbuild-analysis/src/contracts/models.rs +++ b/crates/sqlbuild-analysis/src/contracts/models.rs @@ -5,7 +5,7 @@ pub struct ContractRequest { /// The dialect name Python hands type normalization (`str(dialect or "generic")`). pub dialect: String, - /// Whether `settings.column_contract_mode` is `implicit`. + /// Whether `settings.check_declared_columns` is on. pub implicit_column_contracts: bool, /// Whether the effective table promotion mode is `staged`. pub staged_promotion: bool, diff --git a/crates/sqlbuild-cache/src/hosted_shapes/constants.rs b/crates/sqlbuild-cache/src/hosted_shapes/constants.rs index e5bf80b787..8eaa9be8ec 100644 --- a/crates/sqlbuild-cache/src/hosted_shapes/constants.rs +++ b/crates/sqlbuild-cache/src/hosted_shapes/constants.rs @@ -1,7 +1,7 @@ //! The Python shape names of the natively hosted compiler shapes. /// The Python model type a natively hosted compiler shape is captured as. -pub const HOSTED_SHAPE_TYPES: [(&str, &str); 491] = [ +pub const HOSTED_SHAPE_TYPES: [(&str, &str); 490] = [ ( "sqlbuild._native:AlignedInterval", "sqlbuild.cursor_algebra.models:AlignedInterval", @@ -62,10 +62,6 @@ pub const HOSTED_SHAPE_TYPES: [(&str, &str); 491] = [ "sqlbuild._native:CollectionRendering", "sqlbuild.sql_values.types:CollectionRendering", ), - ( - "sqlbuild._native:ColumnContractMode", - "sqlbuild.spec.contracts.types:ColumnContractMode", - ), ( "sqlbuild._native:ColumnLineage", "sqlbuild.compiler.lineage.models:ColumnLineage", diff --git a/crates/sqlbuild-cli/src/native_commands/_helpers/project_facts.rs b/crates/sqlbuild-cli/src/native_commands/_helpers/project_facts.rs index 1aa95faf73..6d5d7546bd 100644 --- a/crates/sqlbuild-cli/src/native_commands/_helpers/project_facts.rs +++ b/crates/sqlbuild-cli/src/native_commands/_helpers/project_facts.rs @@ -3,15 +3,14 @@ use std::path::Path; use sqlbuild_config::project::main::load_project_config::load_project_config; +use sqlbuild_config::project::main::project_config_paths::project_config_paths; use sqlbuild_config::project::models::{Built, ConfigPaths}; -use sqlbuild_core::constants::PROJECT_CONFIG_FILENAME; use sqlbuild_orchestration::store::errors::ControlError; use crate::native_commands::main::effective_target::effective_target; use crate::native_commands::constants::{ - CUSTOM_RULES_DIRECTORY, EVENT_EXPORTERS_DIRECTORY, LEGACY_LOCAL_CONFIG_FILENAME, - LEGACY_PROJECT_CONFIG_FILENAME, LIFECYCLE_SINK_PATH, LOCAL_CONFIG_FILENAME, SINKS_DIRECTORY, + CUSTOM_RULES_DIRECTORY, EVENT_EXPORTERS_DIRECTORY, LIFECYCLE_SINK_PATH, SINKS_DIRECTORY, }; pub(crate) fn object_field<'a>(built: &'a Built, name: &str) -> Option<&'a Built> { @@ -36,16 +35,6 @@ fn names_lifecycle_sinks(config: &Built) -> bool { } } -/// The four configuration files of `project_dir`. -pub(crate) fn config_paths(project_dir: &Path) -> ConfigPaths { - ConfigPaths { - project: project_dir.join(PROJECT_CONFIG_FILENAME), - legacy_project: project_dir.join(LEGACY_PROJECT_CONFIG_FILENAME), - local: project_dir.join(LOCAL_CONFIG_FILENAME), - legacy_local: project_dir.join(LEGACY_LOCAL_CONFIG_FILENAME), - } -} - /// Whether `discover_runtime_extensions` would import nothing and accept the project file. pub(crate) fn has_no_runtime_extensions(project_dir: &Path) -> bool { if project_dir.join(EVENT_EXPORTERS_DIRECTORY).exists() @@ -53,7 +42,7 @@ pub(crate) fn has_no_runtime_extensions(project_dir: &Path) -> bool { { return false; } - let paths: ConfigPaths = config_paths(project_dir); + let paths: ConfigPaths = project_config_paths(project_dir); if !paths.project.exists() { return true; } diff --git a/crates/sqlbuild-cli/src/native_commands/constants.rs b/crates/sqlbuild-cli/src/native_commands/constants.rs index f1b8a95848..4b7f7d30a8 100644 --- a/crates/sqlbuild-cli/src/native_commands/constants.rs +++ b/crates/sqlbuild-cli/src/native_commands/constants.rs @@ -55,9 +55,6 @@ pub(crate) const SKILL_FILES_HEADER: &str = "Updated SQLBuild skill files:\n"; pub(crate) const RULE_SELECTOR_REQUIRED: &str = "A rule code or family prefix is required"; /// `run_rules_command`'s exit status for a missing or unknown rule. pub(crate) const RULES_USAGE_EXIT_CODE: i32 = 2; -pub(crate) const LEGACY_PROJECT_CONFIG_FILENAME: &str = "sqlbuild_project.yml"; -pub(crate) const LOCAL_CONFIG_FILENAME: &str = "sqlbuild_local.toml"; -pub(crate) const LEGACY_LOCAL_CONFIG_FILENAME: &str = "sqlbuild_local.yml"; /// The class Python's last-resort log handler names for a user error. pub(crate) const USER_ERROR_CLASS: &str = "sqlbuild._native.CliUserError"; pub(crate) const INIT_FAILURE_PREFIX: &str = "sqb init: "; diff --git a/crates/sqlbuild-cli/src/native_commands/main/effective_target.rs b/crates/sqlbuild-cli/src/native_commands/main/effective_target.rs index 5794ca70e3..2169cbeffd 100644 --- a/crates/sqlbuild-cli/src/native_commands/main/effective_target.rs +++ b/crates/sqlbuild-cli/src/native_commands/main/effective_target.rs @@ -7,16 +7,17 @@ use sqlbuild_config::effective::models::TargetChoice; use sqlbuild_config::models::ConfigValue; use sqlbuild_config::project::main::load_local_config::load_local_config; use sqlbuild_config::project::main::load_project_config::load_project_config; +use sqlbuild_config::project::main::project_config_paths::project_config_paths; use sqlbuild_config::project::models::Built; -use crate::native_commands::_helpers::project_facts::{config_paths, object_field}; +use crate::native_commands::_helpers::project_facts::object_field; /// The effective target of `project_dir` with `selected` as `--target`, `None` when nothing selects one. pub fn effective_target( project_dir: &Path, selected: Option, ) -> Result, String> { - let paths = config_paths(project_dir); + let paths = project_config_paths(project_dir); let invalid = |_| "project configuration is invalid; run sqb debug".to_owned(); let project = load_project_config(&paths).map_err(invalid)?; let local = load_local_config(&paths).map_err(invalid)?; diff --git a/crates/sqlbuild-cli/src/replay/_helpers/serving.rs b/crates/sqlbuild-cli/src/replay/_helpers/serving.rs index 482f3b3893..7ec9530209 100644 --- a/crates/sqlbuild-cli/src/replay/_helpers/serving.rs +++ b/crates/sqlbuild-cli/src/replay/_helpers/serving.rs @@ -1,11 +1,13 @@ //! The native reuse check against a launch record and the output a hit replays. -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::time::Instant; use sqlbuild_cache::project_reuse::main::check_reuse::check_reuse; use sqlbuild_cache::project_reuse::main::replay_stdout::replay_stdout; use sqlbuild_cache::project_reuse::models::{ReuseCheck, ReuseOutcome, ReuseRules, StoredOutput}; +use sqlbuild_config::project::main::deprecated_setting_warnings::deprecated_setting_warnings; +use sqlbuild_config::project::main::project_config_paths::project_config_paths; use crate::replay::_helpers::console::tenths_of_seconds; use crate::replay::_helpers::records::{hit_timings, host_identity}; @@ -49,7 +51,12 @@ pub(crate) fn served( let stdout = replay_stdout(output, &timings)?; let (prefix, suffix) = &record.hit_message; let mut stderr = format!("{prefix}{}{suffix}\n", tenths_of_seconds(check_ms)); - for line in &output.stderr_lines { + let warnings: Vec = + match deprecated_setting_warnings(&project_config_paths(Path::new(&record.project_dir))) { + Ok(warnings) => warnings, + Err(_) => return None, + }; + for line in warnings.iter().chain(&output.stderr_lines) { stderr.push_str(line); stderr.push('\n'); } diff --git a/crates/sqlbuild-config/src/project/_helpers/documents.rs b/crates/sqlbuild-config/src/project/_helpers/documents.rs index 5ae9cfb256..3ddb50b887 100644 --- a/crates/sqlbuild-config/src/project/_helpers/documents.rs +++ b/crates/sqlbuild-config/src/project/_helpers/documents.rs @@ -24,8 +24,8 @@ use crate::project::_helpers::targets::{ }; use crate::project::_helpers::values::is_truthy; use crate::project::constants::{ - LEGACY_EVENT_EXPORTERS_KEY, LOCAL_CONFIG_FILENAME, QUERY_CHANGE_TRACKING_KEY, - REQUIRE_SQL_ANALYSIS_KEY, SQL_ANALYSIS_KEY, + COLUMN_CONTRACT_MODES, LEGACY_COLUMN_CONTRACT_MODE_KEY, LEGACY_EVENT_EXPORTERS_KEY, + LOCAL_CONFIG_FILENAME, QUERY_CHANGE_TRACKING_KEY, REQUIRE_SQL_ANALYSIS_KEY, SQL_ANALYSIS_KEY, }; use crate::project::errors::{ConfigFailure, FailureClass, LoadFailure, MessagePiece}; use crate::project::models::{Built, ConfigFile, ConfigPaths, ReviewConfig}; @@ -441,3 +441,36 @@ pub(crate) fn review_config(paths: &ConfigPaths) -> Result Result, LoadFailure> { + let mut warnings: Vec = Vec::new(); + for (local, name) in [ + (false, PROJECT_CONFIG_FILENAME), + (true, LOCAL_CONFIG_FILENAME), + ] { + let file = resolve(paths, local)?; + if !path_of(paths, file).exists() { + continue; + } + if let Some(checked) = legacy_column_contract_mode(&load_toml_mapping(paths, file)?) { + warnings.push(format!( + "Warning: settings.column_contract_mode in {name} is deprecated; replace it with \ + settings.check_declared_columns = {checked}" + )); + } + } + Ok(warnings) +} + +/// The `check_declared_columns` value a valid `[settings] column_contract_mode` alias maps to. +fn legacy_column_contract_mode(table: &ConfigValue) -> Option { + let settings = get(table.as_map()?, SETTINGS_SECTION)?.as_map()?; + let ConfigValue::String(mode) = get(settings, LEGACY_COLUMN_CONTRACT_MODE_KEY)? else { + return None; + }; + COLUMN_CONTRACT_MODES + .iter() + .find(|(value, _)| value == mode) + .map(|(_, checked)| *checked) +} diff --git a/crates/sqlbuild-config/src/project/_helpers/sections.rs b/crates/sqlbuild-config/src/project/_helpers/sections.rs index f787094cac..31016fb3df 100644 --- a/crates/sqlbuild-config/src/project/_helpers/sections.rs +++ b/crates/sqlbuild-config/src/project/_helpers/sections.rs @@ -11,15 +11,16 @@ use crate::project::_helpers::keys::{Place, reject_removed_virtual_keys, validat use crate::project::_helpers::targets::seconds_value; use crate::project::_helpers::values::{int_below, python_equal}; use crate::project::constants::{ - AUDIT_SEVERITIES, COLLECTION_RENDERINGS, COLUMN_CONTRACT_MODES, CONCURRENCY_KEY, - DBT_DEFER_CLONE_KEY, DBT_KEYS, DBT_REMOVED_KEYS, DBT_REUSE_KEYS, DEFAULT_IN_USE_WINDOW, - DEFAULT_QUERY_ARTIFACT_TTL, FUTURE_CURSOR_ACTIONS, LEGACY_CONCURRENCY_KEY, - LEGACY_SQL_VALIDATION_KEY, LOCAL_DBT_KEYS, MAX_BATCHES_KEY, MICROBATCH_LIMIT_ACTIONS, - OLD_NAME_VIEWS_KEY, QUERY_CHANGE_TRACKING_KEY, REQUIRE_SQL_ANALYSIS_KEY, - REVIEW_DOWNSTREAM_POLICIES, REVIEW_KEYS, RUN_NAMESPACE_KEY, RUN_NAMESPACE_MAX_LENGTH, - SCENARIO_KEYS, SETTINGS_KEYS, SNAPSHOT_FULL_REFRESH_POLICIES, SNAPSHOT_KEYS, - SNAPSHOT_LIMIT_KEYS, SNAPSHOT_SCHEMA_CHANGE_POLICIES, SQL_ANALYSIS_KEY, - UNACCOUNTED_PARTITION_POLICIES, USD_PER_CREDIT_KEY, ZERO_FIXED_DURATION, ZERO_FLOAT, + AUDIT_SEVERITIES, CHECK_DECLARED_COLUMNS_KEY, COLLECTION_RENDERINGS, COLUMN_CONTRACT_MODES, + CONCURRENCY_KEY, DBT_DEFER_CLONE_KEY, DBT_KEYS, DBT_REMOVED_KEYS, DBT_REUSE_KEYS, + DEFAULT_IN_USE_WINDOW, DEFAULT_QUERY_ARTIFACT_TTL, FUTURE_CURSOR_ACTIONS, + LEGACY_COLUMN_CONTRACT_MODE_KEY, LEGACY_CONCURRENCY_KEY, LEGACY_SQL_VALIDATION_KEY, + LOCAL_DBT_KEYS, MAX_BATCHES_KEY, MICROBATCH_LIMIT_ACTIONS, OLD_NAME_VIEWS_KEY, + QUERY_CHANGE_TRACKING_KEY, REQUIRE_SQL_ANALYSIS_KEY, REVIEW_DOWNSTREAM_POLICIES, REVIEW_KEYS, + RUN_NAMESPACE_KEY, RUN_NAMESPACE_MAX_LENGTH, SCENARIO_KEYS, SETTINGS_KEYS, + SNAPSHOT_FULL_REFRESH_POLICIES, SNAPSHOT_KEYS, SNAPSHOT_LIMIT_KEYS, + SNAPSHOT_SCHEMA_CHANGE_POLICIES, SQL_ANALYSIS_KEY, UNACCOUNTED_PARTITION_POLICIES, + USD_PER_CREDIT_KEY, ZERO_FIXED_DURATION, ZERO_FLOAT, }; use crate::project::constants::{ DEFAULT_TEST_TIMEOUT, DEFAULT_UNIT_TEST_MAX_REAL_MODELS, DELTA_COMPILE_KEY, DISABLED_VALUE, @@ -101,7 +102,11 @@ fn settings_mapping(payload: Option<&ConfigValue>, file: ConfigFile) -> Loaded<& )?; let allowed: Vec<&str> = SETTINGS_KEYS .into_iter() - .chain([LEGACY_CONCURRENCY_KEY, LEGACY_SQL_VALIDATION_KEY]) + .chain([ + LEGACY_CONCURRENCY_KEY, + LEGACY_SQL_VALIDATION_KEY, + LEGACY_COLUMN_CONTRACT_MODE_KEY, + ]) .collect(); validate_allowed_keys(mapping, &allowed, place(file, "settings"))?; if has(mapping, CONCURRENCY_KEY) && has(mapping, LEGACY_CONCURRENCY_KEY) { @@ -109,6 +114,12 @@ fn settings_mapping(payload: Option<&ConfigValue>, file: ConfigFile) -> Loaded<& "settings cannot define both 'concurrency' and legacy 'max_concurrency'", )); } + if has(mapping, CHECK_DECLARED_COLUMNS_KEY) && has(mapping, LEGACY_COLUMN_CONTRACT_MODE_KEY) { + return Err(ConfigFailure::plain( + "settings cannot define both 'check_declared_columns' and deprecated \ + 'column_contract_mode'; keep only check_declared_columns", + )); + } if let (Some(current), Some(legacy)) = ( get(mapping, SQL_ANALYSIS_KEY), get(mapping, LEGACY_SQL_VALIDATION_KEY), @@ -121,20 +132,27 @@ fn settings_mapping(payload: Option<&ConfigValue>, file: ConfigFile) -> Loaded<& Ok(mapping) } -fn column_contract_mode(mapping: &Entries) -> Loaded { - let mode = match get(mapping, "column_contract_mode") { - None => Some(COLUMN_CONTRACT_MODES[0]), +/// `check_declared_columns`, or what the deprecated `column_contract_mode` it replaces means. +fn check_declared_columns(mapping: &Entries) -> Loaded { + if !has(mapping, LEGACY_COLUMN_CONTRACT_MODE_KEY) { + return optional_bool(mapping, CHECK_DECLARED_COLUMNS_KEY, true); + } + let mode = match get(mapping, LEGACY_COLUMN_CONTRACT_MODE_KEY) { Some(ConfigValue::String(text)) => Some(text.as_str()), - Some(_) => None, + _ => None, }; - match mode { - Some(text) if COLUMN_CONTRACT_MODES.contains(&text) => { - Ok(member("ColumnContractMode", text)) - } - _ => Err(ConfigFailure::plain( - "settings.column_contract_mode must be one of: implicit, explicit", - )), - } + COLUMN_CONTRACT_MODES + .iter() + .find(|(name, _)| Some(*name) == mode) + .map(|(_, checked)| *checked) + .ok_or_else(|| { + ConfigFailure::plain( + "settings.column_contract_mode must be one of: implicit, explicit. It is \ + deprecated; set this in sqlbuild_project.toml instead, with false to leave \ + declared columns unchecked:\n [settings]\n \ + check_declared_columns = true", + ) + }) } fn unaccounted_partition_policy(mapping: &Entries) -> Loaded { @@ -208,7 +226,10 @@ pub(crate) fn load_settings(payload: Option<&ConfigValue>, file: ConfigFile) -> true, )?)), ), - ("column_contract_mode", column_contract_mode(mapping)?), + ( + "check_declared_columns", + Built::Value(ConfigValue::Bool(check_declared_columns(mapping)?)), + ), ( "auto_load_sources", Built::Value(ConfigValue::Bool(optional_bool( @@ -275,6 +296,7 @@ pub(crate) fn setting_overrides(mapping: &Entries) -> Vec { let name = match key_name(key) { LEGACY_CONCURRENCY_KEY => CONCURRENCY_KEY, LEGACY_SQL_VALIDATION_KEY => SQL_ANALYSIS_KEY, + LEGACY_COLUMN_CONTRACT_MODE_KEY => CHECK_DECLARED_COLUMNS_KEY, other if SETTINGS_KEYS.contains(&other) => other, _ => continue, }; diff --git a/crates/sqlbuild-config/src/project/constants.rs b/crates/sqlbuild-config/src/project/constants.rs index c3ae524611..753734ebd8 100644 --- a/crates/sqlbuild-config/src/project/constants.rs +++ b/crates/sqlbuild-config/src/project/constants.rs @@ -1,8 +1,13 @@ //! Project configuration file names, keys and the vocabularies their values come from. pub(crate) const LOCAL_CONFIG_FILENAME: &str = "sqlbuild_local.toml"; +pub(crate) const LEGACY_PROJECT_CONFIG_FILENAME: &str = "sqlbuild_project.yml"; +pub(crate) const LEGACY_LOCAL_CONFIG_FILENAME: &str = "sqlbuild_local.yml"; pub(crate) const SQL_ANALYSIS_KEY: &str = "sql_analysis"; pub(crate) const LEGACY_SQL_VALIDATION_KEY: &str = "sql_validation"; +pub(crate) const CHECK_DECLARED_COLUMNS_KEY: &str = "check_declared_columns"; +/// The deprecated alias of `check_declared_columns`. +pub(crate) const LEGACY_COLUMN_CONTRACT_MODE_KEY: &str = "column_contract_mode"; pub(crate) const REQUIRE_SQL_ANALYSIS_KEY: &str = "require_sql_analysis"; pub(crate) const QUERY_CHANGE_TRACKING_KEY: &str = "query_change_tracking"; pub(crate) const CONCURRENCY_KEY: &str = "concurrency"; @@ -48,7 +53,7 @@ pub(crate) const SETTINGS_KEYS: [&str; 15] = [ "sql_analysis", "require_sql_analysis", "query_change_tracking", - "column_contract_mode", + "check_declared_columns", "concurrency", "auto_load_sources", "microbatch_concurrency", @@ -253,7 +258,9 @@ pub(crate) const SNAPSHOT_SCHEMA_CHANGE_POLICIES: [&str; 3] = ["append_new_columns", "deny", "require_confirmation"]; pub(crate) const UNACCOUNTED_PARTITION_POLICIES: [&str; 3] = ["recover_all", "recover_empty", "synthesize"]; -pub(crate) const COLUMN_CONTRACT_MODES: [&str; 2] = ["implicit", "explicit"]; +/// `column_contract_mode` values and the `check_declared_columns` value each means. +pub(crate) const COLUMN_CONTRACT_MODES: [(&str, bool); 2] = + [("implicit", true), ("explicit", false)]; pub(crate) const AUDIT_SEVERITIES: [&str; 2] = ["warn", "error"]; pub(crate) const COLLECTION_RENDERINGS: [&str; 2] = ["value_list", "array"]; pub(crate) const FUTURE_CURSOR_ACTIONS: [&str; 2] = ["cap", "error"]; diff --git a/crates/sqlbuild-config/src/project/main/deprecated_setting_warnings.rs b/crates/sqlbuild-config/src/project/main/deprecated_setting_warnings.rs new file mode 100644 index 0000000000..37a8cf335e --- /dev/null +++ b/crates/sqlbuild-config/src/project/main/deprecated_setting_warnings.rs @@ -0,0 +1,9 @@ +//! Warnings for deprecated `[settings]` keys that still load as aliases. + +use crate::project::errors::LoadFailure; +use crate::project::models::ConfigPaths; + +/// One `Warning:` line per configuration file that sets a deprecated setting alias. +pub fn deprecated_setting_warnings(paths: &ConfigPaths) -> Result, LoadFailure> { + crate::project::_helpers::documents::deprecated_setting_warnings(paths) +} diff --git a/crates/sqlbuild-config/src/project/main/mod.rs b/crates/sqlbuild-config/src/project/main/mod.rs index 08ec0b599c..8cd4f858ed 100644 --- a/crates/sqlbuild-config/src/project/main/mod.rs +++ b/crates/sqlbuild-config/src/project/main/mod.rs @@ -1,3 +1,4 @@ +pub mod deprecated_setting_warnings; pub mod explicit_references_help; pub mod load_git_base_ref; pub mod load_local_config; @@ -5,6 +6,7 @@ pub mod load_project_config; pub mod load_review_config; pub mod local_sql_analysis_failure; pub mod microbatch_guidance; +pub mod project_config_paths; pub mod resolve_config_file; pub mod setting_help_text; pub mod snippet_help_text; diff --git a/crates/sqlbuild-config/src/project/main/project_config_paths.rs b/crates/sqlbuild-config/src/project/main/project_config_paths.rs new file mode 100644 index 0000000000..9161e08f6c --- /dev/null +++ b/crates/sqlbuild-config/src/project/main/project_config_paths.rs @@ -0,0 +1,20 @@ +//! The configuration files a project directory may hold. + +use std::path::Path; + +use sqlbuild_core::constants::PROJECT_CONFIG_FILENAME; + +use crate::project::constants::{ + LEGACY_LOCAL_CONFIG_FILENAME, LEGACY_PROJECT_CONFIG_FILENAME, LOCAL_CONFIG_FILENAME, +}; +use crate::project::models::ConfigPaths; + +/// The four configuration files of `project_dir`. +pub fn project_config_paths(project_dir: &Path) -> ConfigPaths { + ConfigPaths { + project: project_dir.join(PROJECT_CONFIG_FILENAME), + legacy_project: project_dir.join(LEGACY_PROJECT_CONFIG_FILENAME), + local: project_dir.join(LOCAL_CONFIG_FILENAME), + legacy_local: project_dir.join(LEGACY_LOCAL_CONFIG_FILENAME), + } +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_command/reuse_attempt.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_command/reuse_attempt.rs index 77c109624c..feff66d31e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_command/reuse_attempt.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_command/reuse_attempt.rs @@ -48,6 +48,7 @@ use crate::bindings::_helpers::compile_outputs::json_report::plain_json; use crate::bindings::_helpers::compile_outputs::reuse::{ ReuseCheckPy, ReuseRulesPy, check_compile_reuse, }; +use crate::bindings::_helpers::discovery::project_config::warn_deprecated_settings; use crate::bindings::_helpers::frontier::cache_directory::cache_directory; use crate::bindings::_helpers::macro_bridge::first_compile::keep_delta_claim; use crate::bindings::_helpers::native_host::host; @@ -303,7 +304,7 @@ fn overridden<'py>( /// Replay the stored compile on a hit; the missed attempt when it cannot be replayed. fn replayed<'py>( - native: &Bound<'py, PyAny>, + (native, project_dir): (&Bound<'py, PyAny>, &Bound<'py, PyAny>), missed: Vec<(&'static str, Bound<'py, PyAny>)>, (started, json_output): (f64, bool), ) -> PyResult> { @@ -339,6 +340,7 @@ fn replayed<'py>( py, &format!("{prefix}{seconds:.1}{suffix}").into_bound_py_any(py)?, )?; + warn_deprecated_settings(py, project_dir)?; for line in stderr_lines.try_iter()? { print_stderr(py, &line?)?; } @@ -375,11 +377,10 @@ fn attempt_compile_reuse<'py>(request: &Bound<'py, PyAny>) -> PyResult = native_field(request, "json_output")?; + let project_path: Bound<'py, PyAny> = + imported(py, "pathlib", "Path")?.call1((&project_dir,))?; let mut base: Vec<(&'static str, Bound<'py, PyAny>)> = vec![ - ( - "project_dir", - imported(py, "pathlib", "Path")?.call1((&project_dir,))?, - ), + ("project_dir", project_path.clone()), ("started", started.into_bound_py_any(py)?), ("selected_target", native_field(request, "selected_target")?), ("json_output", json_output.clone()), @@ -410,7 +411,11 @@ fn attempt_compile_reuse<'py>(request: &Bound<'py, PyAny>) -> PyResult = replayed(&native, base, (started, json_output.is_truthy()?))?; + let attempt: Bound<'py, PyAny> = replayed( + (&native, &project_path), + base, + (started, json_output.is_truthy()?), + )?; if native_field(&attempt, "outcome")?.eq(outcome(py, HIT)?)? { write_launch_record(&attempt)?; } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs index df3d5adf9a..c565a917ab 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs @@ -29,7 +29,7 @@ use crate::bindings::_helpers::discovery::model_records::{ ModelFileSelection, discovered_model_files, }; use crate::bindings::_helpers::discovery::project_config::{ - load_local_config_file, load_project_config_file, + load_local_config_file, load_project_config_file, warn_deprecated_settings, }; use crate::bindings::_helpers::discovery::python_function_files::discover_python_function_files; use crate::bindings::_helpers::discovery::python_paths::reject_unsupported_python_paths; @@ -237,6 +237,7 @@ fn assembled_inputs<'py>( project_config: &project_config, local_config: &local_config, })?; + warn_deprecated_settings(py, project_dir)?; reject_unsupported_python_paths(project_dir)?; let delta_settings: &Bound<'py, PyAny> = if native_field(&local_config, "setting_overrides")?.contains(DELTA_COMPILE_SETTING_KEY)? { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compiler_enums/constants.rs b/crates/sqlbuild-python/src/bindings/_helpers/compiler_enums/constants.rs index ce3c261a40..a366d7d457 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compiler_enums/constants.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compiler_enums/constants.rs @@ -369,11 +369,6 @@ const E_MICROBATCH_LIMIT_ACTION: EnumSpec = EnumSpec { ("WARN", "warn"), ], }; -const E_COLUMN_CONTRACT_MODE: EnumSpec = EnumSpec { - name: "ColumnContractMode", - doc: "Default contract behavior for model column declarations.", - members: &[("IMPLICIT", "implicit"), ("EXPLICIT", "explicit")], -}; const E_SOURCE_FRESHNESS_STRATEGY: EnumSpec = EnumSpec { name: "SourceFreshnessStrategy", doc: "", @@ -765,7 +760,6 @@ pub(crate) const COMPILER_ENUMS: &[EnumSpec] = &[ E_SOURCE_WRITE_STRATEGY, E_FUTURE_CURSOR_ACTION, E_MICROBATCH_LIMIT_ACTION, - E_COLUMN_CONTRACT_MODE, E_SOURCE_FRESHNESS_STRATEGY, E_SOURCE_FRESHNESS_VALUE_KIND, E_TIME_TRAVEL_RETENTION_SOURCE, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contract_records/constants.rs b/crates/sqlbuild-python/src/bindings/_helpers/contract_records/constants.rs index 8a268be998..eadc8f712d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contract_records/constants.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/contract_records/constants.rs @@ -197,10 +197,7 @@ const R_SETTINGS_CONFIG: RecordSpec = RecordSpec { FieldSpec::new("sql_analysis", FieldDefault::True), FieldSpec::new("require_sql_analysis", FieldDefault::False), FieldSpec::new("query_change_tracking", FieldDefault::True), - FieldSpec::new( - "column_contract_mode", - FieldDefault::NativeMember(RecordId::ColumnContractMode, "IMPLICIT"), - ), + FieldSpec::new("check_declared_columns", FieldDefault::True), FieldSpec::new("concurrency", FieldDefault::Int(1)), FieldSpec::new("auto_load_sources", FieldDefault::True), FieldSpec::new("microbatch_concurrency", FieldDefault::False), diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contracts/contract_diagnostics.rs b/crates/sqlbuild-python/src/bindings/_helpers/contracts/contract_diagnostics.rs index 0964ef92f3..f8fb99816c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contracts/contract_diagnostics.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/contracts/contract_diagnostics.rs @@ -30,7 +30,6 @@ use crate::bindings::_helpers::records::ids::RecordId; use crate::bindings::_helpers::sqltext::model_headers::{ColumnLocation, location_rows}; const PATHLIB_MODULE: &str = "pathlib"; -const IMPLICIT_COLUMN_CONTRACTS: &str = "implicit"; const GENERIC_DIALECT: &str = "generic"; const OUTPUT_LABEL: &str = "output"; const CONTRACT_PHASE: &str = "contract"; @@ -295,9 +294,8 @@ pub(crate) fn evaluate_model_contracts<'py>( adapter_default: Option<&Bound<'py, PyAny>>, ) -> PyResult> { let settings: Bound<'py, PyAny> = native_field(project, "settings")?; - let mode: String = native_field(&settings, "column_contract_mode")? - .str()? - .extract()?; + let check_declared_columns: bool = + native_field(&settings, "check_declared_columns")?.is_truthy()?; let explicit_promotion: Option = native_field(&settings, "table_promotion_mode")?.extract()?; let promotion: Option = match explicit_promotion { @@ -318,7 +316,7 @@ pub(crate) fn evaluate_model_contracts<'py>( py, ( dialect_name.clone(), - mode == IMPLICIT_COLUMN_CONTRACTS, + check_declared_columns, promotion.as_deref() == Some(STAGED_PROMOTION_MODE), ), &native, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_config.rs b/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_config.rs index 3d594e56e0..536de4c6f2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_config.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_config.rs @@ -9,6 +9,7 @@ use pyo3::prelude::{ use pyo3::types::{PyBytes, PyDict, PyDictMethods, PyFrozenSet, PyString, PyTuple}; use pyo3::{IntoPyObjectExt, pyfunction, wrap_pyfunction}; use sqlbuild_config::project::errors::{ConfigFailure, FailureClass, LoadFailure}; +use sqlbuild_config::project::main::deprecated_setting_warnings::deprecated_setting_warnings; use sqlbuild_config::project::main::load_git_base_ref::load_git_base_ref; use sqlbuild_config::project::main::load_local_config::load_local_config; use sqlbuild_config::project::main::load_project_config::load_project_config; @@ -18,6 +19,7 @@ use sqlbuild_config::project::main::resolve_config_file::resolve_config_file; use sqlbuild_config::project::models::{Built, ConfigFile, ConfigPaths, ReviewConfig}; use crate::bindings::_helpers::boundary::config_values::config_value_to_python; +use crate::bindings::_helpers::native_host::host::write_console; use crate::bindings::_helpers::records::construct::error_class; use crate::bindings::_helpers::records::construct::{new_record, record_class}; use crate::bindings::_helpers::records::ids::ErrorId; @@ -162,6 +164,20 @@ fn built(py: Python<'_>, value: Built) -> PyResult> { } } +/// Write a warning line to stderr for each deprecated setting alias `project_dir` still sets. +pub(crate) fn warn_deprecated_settings( + py: Python<'_>, + project_dir: &Bound<'_, PyAny>, +) -> PyResult<()> { + let files = files(project_dir)?; + match deprecated_setting_warnings(&files.native) { + Ok(warnings) => warnings + .iter() + .try_for_each(|warning| write_console(py, "stderr", &format!("{warning}\n"))), + Err(failure) => Err(load_error(py, &failure, &files)?), + } +} + /// `load_project_config`: the validated `ProjectConfig` of `project_dir`. #[pyfunction] pub(crate) fn load_project_config_file( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/records/ids.rs b/crates/sqlbuild-python/src/bindings/_helpers/records/ids.rs index 15756e1c8e..7c48897c61 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/records/ids.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/records/ids.rs @@ -58,7 +58,6 @@ native_ids! { ClonePolicy => "ClonePolicy", CloneSourcePlanEntry => "CloneSourcePlanEntry", CollectionRendering => "CollectionRendering", - ColumnContractMode => "ColumnContractMode", ColumnLineage => "ColumnLineage", ColumnLineageConfidence => "ColumnLineageConfidence", ColumnLineageEdge => "ColumnLineageEdge", diff --git a/src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/compile.md b/src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/compile.md index 24e26a8b1b..598f2d3363 100644 --- a/src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/compile.md +++ b/src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/compile.md @@ -162,7 +162,7 @@ error[K001]: declared column 'total_cents' was not found in statically inferred --> models/marts/fact_orders.sql:6:5 6 | total_cents (), | ^^^^^^^^^^^ - = help: add total_cents to the SELECT list or correct/remove MODEL(columns (...)); MODEL(columns (...)) is validated using static SQL analysis because settings.column_contract_mode is "implicit" (the default). If this project intentionally uses columns only for metadata and audits, set [settings] column_contract_mode = "explicit"; models with contract enforced remain validated + = help: add total_cents to the SELECT list or correct/remove MODEL(columns (...)); MODEL(columns (...)) is validated using static SQL analysis because settings.check_declared_columns is true (the default). If this project intentionally uses columns only for metadata and audits, set [settings] check_declared_columns = false; models with contract enforced remain validated ``` | Code | Meaning | @@ -172,16 +172,16 @@ error[K001]: declared column 'total_cents' was not found in statically inferred | `K003` | A column's type can't be proven (with `type_enforcement` on) | | `K013` | A string literal fills an enum-typed column of an enforced contract but isn't a member of the enum (not checked on SQL Server) | -Which models are checked depends on `[settings] column_contract_mode`: +Which models are checked depends on `[settings] check_declared_columns`: -- `implicit` (default): a model with declared columns and no `contract` setting must output every +- `true` (default): a model with declared columns and no `contract` setting must output every declared column. -- `explicit`: only models with `contract enforced` are shape-checked; declared columns elsewhere +- `false`: only models with `contract enforced` are shape-checked; declared columns elsewhere are metadata and audit targets. -Explicit type enforcement works in both modes. Switching to `explicit` is a project policy, not a +Explicit type enforcement works with either value. Setting `false` is a project policy, not a way to silence an error: if a model is meant to have a contract, fix the query or the -declaration. Errors on `contract enforced` models don't suggest changing the mode. See +declaration. Errors on `contract enforced` models don't suggest changing the setting. See [Contracts](../concepts/models/contracts.md). ## Output diff --git a/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/models/contracts.md b/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/models/contracts.md index 567a86e07a..efb708a7c5 100644 --- a/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/models/contracts.md +++ b/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/models/contracts.md @@ -15,22 +15,22 @@ Online: https://sqlbuild.com/docs/concepts/models/contracts/ - Adopting an existing schema - Related policies -A model's declared columns provide output metadata, type enforcement, and column audit attachment. The project `column_contract_mode` and model `contract` policy determine whether those declarations also define a statically validated output shape. +A model's declared columns provide output metadata, type enforcement, and column audit attachment. The project `check_declared_columns` setting and model `contract` policy determine whether those declarations also define a statically validated output shape. | Model declaration | Behavior | |-------------------|----------| -| Unspecified | Follow `settings.column_contract_mode`: `implicit` validates declared columns as an open shape; `explicit` treats them as metadata and audit attachment only. | +| Unspecified | Follow `settings.check_declared_columns`: `true` validates declared columns as an open shape; `false` treats them as metadata and audit attachment only. | | `none` | Do not activate declared-shape or nullability contract validation for this model. Explicit type enforcement remains active. | | `enforced` | Treat declared columns as the complete authoritative output shape and enable runtime exact-schema checks on supported materializations. | -The project default is `column_contract_mode = "implicit"`, which preserves SQLBuild's original behavior. Projects that use column declarations primarily for metadata and audits, including migrations from dbt, can opt into explicit contracts: +The project default is `check_declared_columns = true`. Projects that use column declarations primarily for metadata and audits, including migrations from dbt, can turn the check off: ```toml [settings] -column_contract_mode = "explicit" +check_declared_columns = false ``` -Under explicit mode, a model must declare `contract enforced` to activate shape validation. A model-level `contract enforced` or `contract none` always overrides the project mode. +With `check_declared_columns = false`, a model must declare `contract enforced` to activate shape validation, the same as every other model declaring `contract none`. A model-level `contract enforced` or `contract none` always overrides the project setting. ```sql MODEL ( @@ -59,7 +59,7 @@ When declared-shape validation is active and SQL analysis can infer the model's If SQLBuild cannot infer the output shape, these static shape checks cannot run. An enforced contract additionally requires a non-empty column declaration and adds runtime requirements on supported materializations. -Type enforcement remains independent. Typed columns continue to receive static type checks and supported runtime casts under explicit mode and `contract none`. +Type enforcement remains independent. Typed columns continue to receive static type checks and supported runtime casts with `check_declared_columns = false` and `contract none`. Configuration fields that reference output columns, including `unique_key`, `cursor`, `updated_at`, and `check_columns`, are checked against an enforced declaration. @@ -168,6 +168,6 @@ non-projection uses such as `join_on`, `where`, `group_by`, and `window_order_by ## Related policies -The project default is implicit open-shape validation for models that omit `contract`. A repository can select explicit opt-in contracts with `settings.column_contract_mode = "explicit"` or configure a custom [Rule](../rules/custom-rules/overview.md) that requires enforced contracts for selected model families. +The project default checks declared columns as an open shape for models that omit `contract`. A repository can require an explicit `contract enforced` instead with `settings.check_declared_columns = false` or configure a custom [Rule](../rules/custom-rules/overview.md) that requires enforced contracts for selected model families. Contracts also constrain schema-change behavior. For example, `snapshot_schema_change append_new_columns` is incompatible with `contract enforced` because an unannounced appended column would violate the exact declaration. diff --git a/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/models/schemas.md b/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/models/schemas.md index 962fc40bd8..99d7255c66 100644 --- a/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/models/schemas.md +++ b/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/models/schemas.md @@ -139,7 +139,7 @@ Physical SQL output order is not currently enforced. Static contract analysis ma ## Contracts and planning -`contract enforced` treats the complete named-plus-local declaration as the exact output shape. An unspecified model follows the project's `column_contract_mode`; `contract none` explicitly keeps the resolved columns as metadata, audit attachment, and type-enforcement inputs without activating shape validation. See [Contracts](contracts.md). +`contract enforced` treats the complete named-plus-local declaration as the exact output shape. An unspecified model follows the project's `check_declared_columns` setting; `contract none` explicitly keeps the resolved columns as metadata, audit attachment, and type-enforcement inputs without activating shape validation. See [Contracts](contracts.md). For models bound to a reusable schema, effective column names, types, nullability, and enum members participate in model version identity. Changing those fields on a parent therefore affects models bound through descendants. Descriptions do not change model identity. Audits have their own audit-gate identities, so audit changes invalidate reusable audit results without changing the model version itself. diff --git a/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/project-configuration.md b/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/project-configuration.md index 9fa72d06df..a3bea98e9c 100644 --- a/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/project-configuration.md +++ b/src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/project-configuration.md @@ -653,7 +653,7 @@ Global feature toggles: sql_analysis = true require_sql_analysis = false query_change_tracking = true -column_contract_mode = "implicit" +check_declared_columns = true concurrency = 1 microbatch_concurrency = false auto_load_sources = true @@ -671,7 +671,7 @@ delta_compile = true | `sql_analysis` | `true` | Enable SQL syntax analysis, column binding, type inference, output inference, and semantic validation at compile time | | `require_sql_analysis` | `false` | Allow `sql_analysis false` (in a MODEL header or a `[path_defaults]` entry) only on models whose SQL the parser cannot read, and reject `[settings] sql_analysis = false` in `sqlbuild_local.toml`. Project file only. See [SQL analysis](models/configuration.md#sql-analysis). | | `query_change_tracking` | `true` | Track query fingerprints for change detection. A fingerprint covers the SQL tokens of the compiled query and ignores whitespace, comments, and the letter case of reserved keywords and built-in function names, so formatting-only edits do not rebuild. Every other word, including non-reserved keywords, identifiers, aliases, JSON path keys and user-defined function names, counts exactly, as do string literals, quoted identifiers, numbers, and optimizer hints. | -| `column_contract_mode` | `implicit` | Controls whether column declarations on models without a `contract` declaration activate static shape/nullability validation. `implicit` preserves that validation; `explicit` treats columns as metadata and audit attachment unless the model declares `contract enforced`. Model-level `contract enforced` and `contract none` override this setting. Explicit type enforcement remains independent. See [Contracts](models/contracts.md). | +| `check_declared_columns` | `true` | Controls whether column declarations on models without a `contract` declaration activate static shape/nullability validation. `true` checks that every declared column is in the SELECT and checks its nullability; `false` treats columns as metadata and audit attachment unless the model declares `contract enforced`. Model-level `contract enforced` and `contract none` override this setting. Explicit type enforcement remains independent. See [Contracts](models/contracts.md). | | `concurrency` | `1` | Default number of worker connections for commands that run resources in parallel, such as `sqb build`, `sqb test`, `sqb audit`, and `sqb seed`, and for `sqb janitor` actions on warehouses that run DDL concurrently; a target's `concurrency` and `--concurrency` override it (see [Target concurrency](#target-concurrency)) | | `microbatch_concurrency` | `false` | Explicitly permit models with `batch_concurrency > 1`; concurrent batches use immutable coordination facts | | `auto_load_sources` | `true` | Automatically run source loaders before building dependent models during `sqb build`. See [Loaders](python-nodes/loaders.md). | diff --git a/src/sqlbuild/_native.pyi b/src/sqlbuild/_native.pyi index 4e017a8fff..a77ff62373 100644 --- a/src/sqlbuild/_native.pyi +++ b/src/sqlbuild/_native.pyi @@ -11665,12 +11665,6 @@ class MicrobatchLimitAction(StrEnum): ERROR = "error" WARN = "warn" -class ColumnContractMode(StrEnum): - """Default contract behavior for model column declarations.""" - - IMPLICIT = "implicit" - EXPLICIT = "explicit" - class SourceFreshnessStrategy(StrEnum): ADAPTER = "adapter" COLUMN = "column" @@ -11958,7 +11952,7 @@ class SettingsConfig(NativeRecord): sql_analysis: bool require_sql_analysis: bool query_change_tracking: bool - column_contract_mode: ColumnContractMode + check_declared_columns: bool concurrency: int auto_load_sources: bool microbatch_concurrency: bool @@ -11977,7 +11971,7 @@ class SettingsConfig(NativeRecord): sql_analysis: bool = ..., require_sql_analysis: bool = ..., query_change_tracking: bool = ..., - column_contract_mode: ColumnContractMode = ..., + check_declared_columns: bool = ..., concurrency: int = ..., auto_load_sources: bool = ..., microbatch_concurrency: bool = ..., diff --git a/tests/e2e/src/sqlbuild/cli/commands/main/compile/_test_types.py b/tests/e2e/src/sqlbuild/cli/commands/main/compile/_test_types.py index 6771ac246c..8ce02d930a 100644 --- a/tests/e2e/src/sqlbuild/cli/commands/main/compile/_test_types.py +++ b/tests/e2e/src/sqlbuild/cli/commands/main/compile/_test_types.py @@ -714,6 +714,15 @@ class CompileReuseCorruptEntryTestCase: expected_restored_reused: bool = True +@dataclass(frozen=True) +class CompileReuseDeprecatedSettingTestCase: + """A deprecated setting alias whose warning every compile, reused or not, must print once.""" + + description: str + settings_line: str + expected_warning: str + + @dataclass(frozen=True) class CompileReuseReplayTestCase: """One compile whose replay must reproduce output, notes, and exit code.""" diff --git a/tests/e2e/src/sqlbuild/cli/commands/main/compile/helpers.py b/tests/e2e/src/sqlbuild/cli/commands/main/compile/helpers.py index 978b2a6221..e7e6b97035 100644 --- a/tests/e2e/src/sqlbuild/cli/commands/main/compile/helpers.py +++ b/tests/e2e/src/sqlbuild/cli/commands/main/compile/helpers.py @@ -1762,7 +1762,7 @@ def _layered_write_project_config(*, project_dir: Path, compiler_only: bool = Fa database = ":memory:" [settings] -column_contract_mode = "explicit" +check_declared_columns = false [vars] benchmark_revision = "0" diff --git a/tests/e2e/src/sqlbuild/cli/commands/main/compile/test_compile_reuse.py b/tests/e2e/src/sqlbuild/cli/commands/main/compile/test_compile_reuse.py index e86653a59d..7492bb0f94 100644 --- a/tests/e2e/src/sqlbuild/cli/commands/main/compile/test_compile_reuse.py +++ b/tests/e2e/src/sqlbuild/cli/commands/main/compile/test_compile_reuse.py @@ -16,6 +16,7 @@ CompileReuseBypassTestCase, CompileReuseConcurrentWriterTestCase, CompileReuseCorruptEntryTestCase, + CompileReuseDeprecatedSettingTestCase, CompileReuseEventTestCase, CompileReuseHitTestCase, CompileReuseInvalidationTestCase, @@ -570,6 +571,56 @@ def test_given_failed_text_compile_when_rerun_then_report_notes_and_exit_code_ar assert compile_notes(stderr=warm.stderr) == compile_notes(stderr=cold.stderr) +@pytest.mark.parametrize( + "test_case", + [ + CompileReuseDeprecatedSettingTestCase( + description="column_contract_mode_alias", + settings_line='column_contract_mode = "explicit"', + expected_warning=( + "Warning: settings.column_contract_mode in sqlbuild_project.toml is deprecated; " + "replace it with settings.check_declared_columns = false" + ), + ) + ], + ids=lambda case: case.description, +) +def test_given_deprecated_setting_alias_when_compile_is_reused_then_the_warning_still_prints_once( + compile_reuse_project: Path, + test_case: CompileReuseDeprecatedSettingTestCase, + monkeypatch: pytest.MonkeyPatch, + capsys: pytest.CaptureFixture[str], +) -> None: + project_dir: Path = compile_reuse_project + replace_project_text( + project_dir, "sqlbuild_project.toml", "[settings]", f"[settings]\n{test_case.settings_line}" + ) + + cold: subprocess.CompletedProcess[str] = run_reuse_text_compile( + project_dir=project_dir, args=() + ) + warm: subprocess.CompletedProcess[str] = run_reuse_text_compile( + project_dir=project_dir, args=() + ) + enable_compile_reuse(monkeypatch) + _ = compile_in_process_output(project_dir=project_dir, capsys=capsys) + in_process: tuple[int, str, str] = compile_in_process_output( + project_dir=project_dir, capsys=capsys + ) + + assert (cold.returncode, warm.returncode, in_process[0]) == (0, 0, 0), cold.stderr + assert (COMPILE_REUSE_HIT_LINE in warm.stderr, COMPILE_REUSE_HIT_LINE in in_process[2]) == ( + True, + True, + ) + assert ( + cold.stderr.count(test_case.expected_warning), + warm.stderr.count(test_case.expected_warning), + in_process[2].count(test_case.expected_warning), + ) == (1, 1, 1) + assert test_case.expected_warning not in cold.stdout + warm.stdout + in_process[1] + + @pytest.mark.parametrize( "test_case", [ diff --git a/tests/e2e/src/sqlbuild/cli/commands/main/compile/test_resource_sql_validation.py b/tests/e2e/src/sqlbuild/cli/commands/main/compile/test_resource_sql_validation.py index 4aba6f1718..080e5b435d 100644 --- a/tests/e2e/src/sqlbuild/cli/commands/main/compile/test_resource_sql_validation.py +++ b/tests/e2e/src/sqlbuild/cli/commands/main/compile/test_resource_sql_validation.py @@ -210,13 +210,13 @@ ), ), ResourceSqlValidationCase( - description="explicit column contracts report each built-in audit once at the header", + description="unchecked declared columns report each built-in audit once at the header", files=( ( "sqlbuild_project.toml", 'name = "orders"\nadapter = "duckdb"\n\n[connection]\n' 'database = "warehouse.duckdb"\n\n' - '[settings]\ncolumn_contract_mode = "explicit"\n', + "[settings]\ncheck_declared_columns = false\n", ), resource_sql_orders_model(", columns (shipped_at (audits [not_null, unique]))"), ), diff --git a/tests/goldens/compiler/failure/contract-implicit-missing-column.json b/tests/goldens/compiler/failure/contract-implicit-missing-column.json index 87a901d28f..5e7e902f31 100644 --- a/tests/goldens/compiler/failure/contract-implicit-missing-column.json +++ b/tests/goldens/compiler/failure/contract-implicit-missing-column.json @@ -22,7 +22,7 @@ "end_line": 6, "end_column": 16 }, - "help": "add order_count to the SELECT list or correct/remove MODEL(columns (...)); MODEL(columns (...)) is validated using static SQL analysis because settings.column_contract_mode is \"implicit\" (the default). If this project intentionally uses columns only for metadata and audits, set [settings] column_contract_mode = \"explicit\"; models with contract enforced remain validated" + "help": "add order_count to the SELECT list or correct/remove MODEL(columns (...)); MODEL(columns (...)) is validated using static SQL analysis because settings.check_declared_columns is true (the default). If this project intentionally uses columns only for metadata and audits, set [settings] check_declared_columns = false; models with contract enforced remain validated" } ] } diff --git a/tests/goldens/compiler/failure/local-config-unknown-key.json b/tests/goldens/compiler/failure/local-config-unknown-key.json index d8b2adc939..5b94d037c0 100644 --- a/tests/goldens/compiler/failure/local-config-unknown-key.json +++ b/tests/goldens/compiler/failure/local-config-unknown-key.json @@ -8,7 +8,7 @@ "phase": "compile", "severity": "error", "code": "D001", - "message": "/sqlbuild_local.toml settings contains unknown key(s): sql_analysiss. Allowed keys: auto_load_sources, column_contract_mode, concurrency, default_audit_run_scope, default_audit_severity, delta_compile, max_concurrency, microbatch_concurrency, microbatch_unaccounted_partition_policy, query_change_tracking, require_sql_analysis, scenario_timeout, sql_analysis, sql_validation, table_promotion_mode, test_timeout, unit_test_max_real_models", + "message": "/sqlbuild_local.toml settings contains unknown key(s): sql_analysiss. Allowed keys: auto_load_sources, check_declared_columns, column_contract_mode, concurrency, default_audit_run_scope, default_audit_severity, delta_compile, max_concurrency, microbatch_concurrency, microbatch_unaccounted_partition_policy, query_change_tracking, require_sql_analysis, scenario_timeout, sql_analysis, sql_validation, table_promotion_mode, test_timeout, unit_test_max_real_models", "help": "did you mean 'sql_analysis'?" } ] diff --git a/tests/goldens/python_oracle/contracts_generated_enforced_implicit_typed_nullability_and_dynamic_contracts.json b/tests/goldens/python_oracle/contracts_generated_enforced_implicit_typed_nullability_and_dynamic_contracts.json index efc56c9b9c..d87c26b267 100644 --- a/tests/goldens/python_oracle/contracts_generated_enforced_implicit_typed_nullability_and_dynamic_contracts.json +++ b/tests/goldens/python_oracle/contracts_generated_enforced_implicit_typed_nullability_and_dynamic_contracts.json @@ -2,13 +2,13 @@ [ "contracts", { -"None": "9f697d91a5bd8293d4c78868", -"duckdb": "946a3061a7e72843e29b93c8", -"postgres": "946a3061a7e72843e29b93c8", -"snowflake": "946a3061a7e72843e29b93c8", -"bigquery": "9f697d91a5bd8293d4c78868", -"databricks": "9f697d91a5bd8293d4c78868", -"tsql": "9f697d91a5bd8293d4c78868" +"None": "4468a1d48f518ca4b4400c5c", +"duckdb": "fb8ce81c5da3b37b19f0ea97", +"postgres": "fb8ce81c5da3b37b19f0ea97", +"snowflake": "fb8ce81c5da3b37b19f0ea97", +"bigquery": "4468a1d48f518ca4b4400c5c", +"databricks": "4468a1d48f518ca4b4400c5c", +"tsql": "4468a1d48f518ca4b4400c5c" } ], [ @@ -74,37 +74,37 @@ [ "contracts", { -"None": "15c4bcdde1ae6d0d695d8fd6", -"duckdb": "0b6e350a4f4afde493cb8626", -"postgres": "0b6e350a4f4afde493cb8626", -"snowflake": "0b6e350a4f4afde493cb8626", -"bigquery": "15c4bcdde1ae6d0d695d8fd6", -"databricks": "6a937f42b20fa1400d4c5fe7", -"tsql": "6a937f42b20fa1400d4c5fe7" +"None": "1c392cf2d73a90f3c80dad28", +"duckdb": "e18a4843a99d4d6b392e62e6", +"postgres": "e18a4843a99d4d6b392e62e6", +"snowflake": "e18a4843a99d4d6b392e62e6", +"bigquery": "1c392cf2d73a90f3c80dad28", +"databricks": "ef256ae041280e749a74f413", +"tsql": "ef256ae041280e749a74f413" } ], [ "contracts", { -"None": "055df6be920a595cb3395d9f", -"duckdb": "ec97cc8e40b7631612395b21", -"postgres": "ec97cc8e40b7631612395b21", -"snowflake": "ec97cc8e40b7631612395b21", -"bigquery": "ec97cc8e40b7631612395b21", -"databricks": "055df6be920a595cb3395d9f", -"tsql": "ec97cc8e40b7631612395b21" +"None": "46295ba50f2cde3366f7b416", +"duckdb": "108a218293b3667249e9dd19", +"postgres": "108a218293b3667249e9dd19", +"snowflake": "108a218293b3667249e9dd19", +"bigquery": "108a218293b3667249e9dd19", +"databricks": "46295ba50f2cde3366f7b416", +"tsql": "108a218293b3667249e9dd19" } ], [ "contracts", { -"None": "a428eb672c78b30d5702cafd", -"duckdb": "a428eb672c78b30d5702cafd", -"postgres": "a428eb672c78b30d5702cafd", -"snowflake": "a428eb672c78b30d5702cafd", -"bigquery": "a428eb672c78b30d5702cafd", -"databricks": "a428eb672c78b30d5702cafd", -"tsql": "a428eb672c78b30d5702cafd" +"None": "146e877ec8ad652843abfb41", +"duckdb": "146e877ec8ad652843abfb41", +"postgres": "146e877ec8ad652843abfb41", +"snowflake": "146e877ec8ad652843abfb41", +"bigquery": "146e877ec8ad652843abfb41", +"databricks": "146e877ec8ad652843abfb41", +"tsql": "146e877ec8ad652843abfb41" } ], [ @@ -158,13 +158,13 @@ [ "contracts", { -"None": "4488a1489430ab1c4db97e43", -"duckdb": "9a8e3bcf9632a8cf5e072c2c", -"postgres": "9a8e3bcf9632a8cf5e072c2c", -"snowflake": "9a8e3bcf9632a8cf5e072c2c", -"bigquery": "4488a1489430ab1c4db97e43", -"databricks": "4488a1489430ab1c4db97e43", -"tsql": "08c3cbe345575b9a053f2bf4" +"None": "56b5543509d06fb1c21041d1", +"duckdb": "a0b8e7d3875bf00e35b31b3a", +"postgres": "a0b8e7d3875bf00e35b31b3a", +"snowflake": "a0b8e7d3875bf00e35b31b3a", +"bigquery": "56b5543509d06fb1c21041d1", +"databricks": "56b5543509d06fb1c21041d1", +"tsql": "432f00f3da7c20ccd3f577b8" } ], [ @@ -182,13 +182,13 @@ [ "contracts", { -"None": "64f58724212d29d25c0e3f1d", -"duckdb": "23893ae7f9f05f0777697eba", -"postgres": "23893ae7f9f05f0777697eba", -"snowflake": "23893ae7f9f05f0777697eba", -"bigquery": "64f58724212d29d25c0e3f1d", -"databricks": "23893ae7f9f05f0777697eba", -"tsql": "23893ae7f9f05f0777697eba" +"None": "5a5871fa04d9a20d7711baf0", +"duckdb": "d321e9f172844d14d14f673b", +"postgres": "d321e9f172844d14d14f673b", +"snowflake": "d321e9f172844d14d14f673b", +"bigquery": "5a5871fa04d9a20d7711baf0", +"databricks": "d321e9f172844d14d14f673b", +"tsql": "d321e9f172844d14d14f673b" } ], [ @@ -206,13 +206,13 @@ [ "contracts", { -"None": "413e569c6194a415092ae35d", -"duckdb": "a2cbcbd14fe4ea1524c2a97a", -"postgres": "a2cbcbd14fe4ea1524c2a97a", -"snowflake": "a2cbcbd14fe4ea1524c2a97a", -"bigquery": "aaea819afff0f389c94a3eb8", -"databricks": "aaea819afff0f389c94a3eb8", -"tsql": "aaea819afff0f389c94a3eb8" +"None": "b9d3101365e641510618cd78", +"duckdb": "28f367dbe9edd587d885c1b0", +"postgres": "28f367dbe9edd587d885c1b0", +"snowflake": "28f367dbe9edd587d885c1b0", +"bigquery": "c5a75f9cfcaa4e7fab58ab34", +"databricks": "c5a75f9cfcaa4e7fab58ab34", +"tsql": "c5a75f9cfcaa4e7fab58ab34" } ], [ @@ -314,13 +314,13 @@ [ "contracts", { -"None": "693ade4356c6087b9c1d8b19", -"duckdb": "693ade4356c6087b9c1d8b19", -"postgres": "693ade4356c6087b9c1d8b19", -"snowflake": "693ade4356c6087b9c1d8b19", -"bigquery": "693ade4356c6087b9c1d8b19", -"databricks": "693ade4356c6087b9c1d8b19", -"tsql": "693ade4356c6087b9c1d8b19" +"None": "52cdcd511bf9153b96f8c816", +"duckdb": "52cdcd511bf9153b96f8c816", +"postgres": "52cdcd511bf9153b96f8c816", +"snowflake": "52cdcd511bf9153b96f8c816", +"bigquery": "52cdcd511bf9153b96f8c816", +"databricks": "52cdcd511bf9153b96f8c816", +"tsql": "52cdcd511bf9153b96f8c816" } ], [ @@ -410,13 +410,13 @@ [ "contracts", { -"None": "48415c26019755009787f14c", -"duckdb": "cd5296ac257b6e4f10c3000d", -"postgres": "cd5296ac257b6e4f10c3000d", -"snowflake": "cd5296ac257b6e4f10c3000d", -"bigquery": "48415c26019755009787f14c", -"databricks": "48415c26019755009787f14c", -"tsql": "cd5296ac257b6e4f10c3000d" +"None": "e1a7960080040014cb5afaec", +"duckdb": "a95fa25696abf1140e7c0000", +"postgres": "a95fa25696abf1140e7c0000", +"snowflake": "a95fa25696abf1140e7c0000", +"bigquery": "e1a7960080040014cb5afaec", +"databricks": "e1a7960080040014cb5afaec", +"tsql": "a95fa25696abf1140e7c0000" } ], [ @@ -446,13 +446,13 @@ [ "contracts", { -"None": "f6dafe38c2aa2436ad17d2e6", -"duckdb": "f6dafe38c2aa2436ad17d2e6", -"postgres": "afb26acda81b184518d6d6f5", -"snowflake": "f6dafe38c2aa2436ad17d2e6", -"bigquery": "f6dafe38c2aa2436ad17d2e6", -"databricks": "f6dafe38c2aa2436ad17d2e6", -"tsql": "afb26acda81b184518d6d6f5" +"None": "f4c3b90723d3035642621697", +"duckdb": "f4c3b90723d3035642621697", +"postgres": "48f4d5904e4ba757feadf37f", +"snowflake": "f4c3b90723d3035642621697", +"bigquery": "f4c3b90723d3035642621697", +"databricks": "f4c3b90723d3035642621697", +"tsql": "48f4d5904e4ba757feadf37f" } ], [ @@ -494,37 +494,37 @@ [ "contracts", { -"None": "6242d56d5832fdeefd826de9", -"duckdb": "6242d56d5832fdeefd826de9", -"postgres": "7d8609a5dcd3a0f32d347465", -"snowflake": "7d8609a5dcd3a0f32d347465", -"bigquery": "6242d56d5832fdeefd826de9", -"databricks": "6242d56d5832fdeefd826de9", -"tsql": "6242d56d5832fdeefd826de9" +"None": "2f4d4854052e5b2c341be511", +"duckdb": "2f4d4854052e5b2c341be511", +"postgres": "352658b79bb1cfd0ad1faf6e", +"snowflake": "352658b79bb1cfd0ad1faf6e", +"bigquery": "2f4d4854052e5b2c341be511", +"databricks": "2f4d4854052e5b2c341be511", +"tsql": "2f4d4854052e5b2c341be511" } ], [ "contracts", { -"None": "8dd6f78d1bbd41f3f2f556fb", -"duckdb": "8dd6f78d1bbd41f3f2f556fb", -"postgres": "8dd6f78d1bbd41f3f2f556fb", -"snowflake": "8dd6f78d1bbd41f3f2f556fb", -"bigquery": "8dd6f78d1bbd41f3f2f556fb", -"databricks": "8dd6f78d1bbd41f3f2f556fb", -"tsql": "8dd6f78d1bbd41f3f2f556fb" +"None": "670c69c37d74aceab22e1515", +"duckdb": "670c69c37d74aceab22e1515", +"postgres": "670c69c37d74aceab22e1515", +"snowflake": "670c69c37d74aceab22e1515", +"bigquery": "670c69c37d74aceab22e1515", +"databricks": "670c69c37d74aceab22e1515", +"tsql": "670c69c37d74aceab22e1515" } ], [ "contracts", { -"None": "12a74be4926070cf6793cb4d", -"duckdb": "12a74be4926070cf6793cb4d", -"postgres": "12a74be4926070cf6793cb4d", -"snowflake": "12a74be4926070cf6793cb4d", -"bigquery": "891f3d8b2c293698577c7813", -"databricks": "12a74be4926070cf6793cb4d", -"tsql": "12a74be4926070cf6793cb4d" +"None": "140bc939bff7e716152dd27f", +"duckdb": "140bc939bff7e716152dd27f", +"postgres": "140bc939bff7e716152dd27f", +"snowflake": "140bc939bff7e716152dd27f", +"bigquery": "c9b6c5f365bc3fe054e4faf2", +"databricks": "140bc939bff7e716152dd27f", +"tsql": "140bc939bff7e716152dd27f" } ], [ @@ -554,13 +554,13 @@ [ "contracts", { -"None": "3c9b74c5b22f656137431938", -"duckdb": "3c9b74c5b22f656137431938", -"postgres": "3c9b74c5b22f656137431938", -"snowflake": "3c9b74c5b22f656137431938", -"bigquery": "3c9b74c5b22f656137431938", -"databricks": "3c9b74c5b22f656137431938", -"tsql": "3c9b74c5b22f656137431938" +"None": "2e2853705c0438a8d2843b23", +"duckdb": "2e2853705c0438a8d2843b23", +"postgres": "2e2853705c0438a8d2843b23", +"snowflake": "2e2853705c0438a8d2843b23", +"bigquery": "2e2853705c0438a8d2843b23", +"databricks": "2e2853705c0438a8d2843b23", +"tsql": "2e2853705c0438a8d2843b23" } ], [ @@ -578,13 +578,13 @@ [ "contracts", { -"None": "66a6ebf5f8418cf0d816c167", -"duckdb": "cc37eb626963366490c09c21", -"postgres": "a8bc34d679ed5c1bd41c17ba", -"snowflake": "0f72c2e3063cc166300becea", -"bigquery": "be7b04ec20ebcdd8742b4180", -"databricks": "cc37eb626963366490c09c21", -"tsql": "cc58014488337d803da83131" +"None": "73203819b605274b38ecbfc1", +"duckdb": "1931b18fcefdffb99b7a688e", +"postgres": "b86830e946240d5b5ea2ddfb", +"snowflake": "2ac8be57d53f848825b50251", +"bigquery": "9fe54d0db7dd91047e65e441", +"databricks": "1931b18fcefdffb99b7a688e", +"tsql": "559bc7c88585130792649498" } ], [ @@ -614,25 +614,25 @@ [ "contracts", { -"None": "bdca9fd6b5122e6999d67907", -"duckdb": "a39ffda7852644471dc4cd01", -"postgres": "a39ffda7852644471dc4cd01", -"snowflake": "a39ffda7852644471dc4cd01", -"bigquery": "81109ce0b75717f432eec784", -"databricks": "81109ce0b75717f432eec784", -"tsql": "bdca9fd6b5122e6999d67907" +"None": "0a6c32f28f1f118fce837b44", +"duckdb": "ce8519ac3ae2285f86bace8f", +"postgres": "ce8519ac3ae2285f86bace8f", +"snowflake": "ce8519ac3ae2285f86bace8f", +"bigquery": "94d3833106fff9f1cd81f8ca", +"databricks": "94d3833106fff9f1cd81f8ca", +"tsql": "0a6c32f28f1f118fce837b44" } ], [ "contracts", { -"None": "257b09b04f10f75c5c4e4c2e", -"duckdb": "257b09b04f10f75c5c4e4c2e", -"postgres": "3405db15b2687320907ae528", -"snowflake": "3405db15b2687320907ae528", -"bigquery": "257b09b04f10f75c5c4e4c2e", -"databricks": "3405db15b2687320907ae528", -"tsql": "257b09b04f10f75c5c4e4c2e" +"None": "b0f4ff7bdb22e70450bb554d", +"duckdb": "b0f4ff7bdb22e70450bb554d", +"postgres": "5bfc18d5575fdbfd78f984f8", +"snowflake": "5bfc18d5575fdbfd78f984f8", +"bigquery": "b0f4ff7bdb22e70450bb554d", +"databricks": "5bfc18d5575fdbfd78f984f8", +"tsql": "b0f4ff7bdb22e70450bb554d" } ], [ @@ -662,13 +662,13 @@ [ "contracts", { -"None": "197e3351cf8e73647dafe210", -"duckdb": "70130ae9c4f7aa6a50756c6b", -"postgres": "70130ae9c4f7aa6a50756c6b", -"snowflake": "70130ae9c4f7aa6a50756c6b", -"bigquery": "197e3351cf8e73647dafe210", -"databricks": "2eb73b6d0fe25a8e439c0023", -"tsql": "af787848beb1bd413e6f9348" +"None": "c5796b1c6cdb1a297bae8709", +"duckdb": "8aaa2d458624305a775a549c", +"postgres": "8aaa2d458624305a775a549c", +"snowflake": "8aaa2d458624305a775a549c", +"bigquery": "c5796b1c6cdb1a297bae8709", +"databricks": "7fa6d9440f21a20015a8c4af", +"tsql": "c01c95754b2dfa4678b0cb01" } ], [ diff --git a/tests/integration/src/sqlbuild/compiler/contracts/helpers.py b/tests/integration/src/sqlbuild/compiler/contracts/helpers.py index 1f6c0b4873..22f6abcf2f 100644 --- a/tests/integration/src/sqlbuild/compiler/contracts/helpers.py +++ b/tests/integration/src/sqlbuild/compiler/contracts/helpers.py @@ -13,7 +13,6 @@ import sqlbuild._native as native_module from sqlbuild._native import ( - ColumnContractMode, CompilerDiagnostic, ContractPolicy, ContractValidationResult, @@ -191,7 +190,7 @@ def perturbed_project(*, project: CompiledProjectView, rng: random.Random) -> Co native_project=None, settings=replace( project.settings, - column_contract_mode=rng.choice(tuple(ColumnContractMode)), + check_declared_columns=rng.choice((True, False)), table_promotion_mode=rng.choice(_PROMOTION_MODES), ), models=tuple(perturbed_model(model=model, rng=rng) for model in project.models), @@ -338,7 +337,7 @@ def contract_statuses( request: NativeContractRequest = ( "", - project.settings.column_contract_mode == ColumnContractMode.IMPLICIT, + project.settings.check_declared_columns, [_status_row(model) for model in project.models], ) return native_contract_statuses(request=request, diagnostics=len(result.diagnostics)) diff --git a/tests/native_field_fallbacks.txt b/tests/native_field_fallbacks.txt index b9818f784f..e02c35787b 100644 --- a/tests/native_field_fallbacks.txt +++ b/tests/native_field_fallbacks.txt @@ -199,7 +199,6 @@ crates/sqlbuild-python/src/bindings/_helpers/frontier/encoder.rs BindingCatalog. crates/sqlbuild-python/src/bindings/_helpers/frontier/encoder.rs BindingCatalog.quoted_ignore_case crates/sqlbuild-python/src/bindings/_helpers/frontier/encoder.rs BindingCatalog.schemas crates/sqlbuild-python/src/bindings/_helpers/frontier/encoder.rs CollectionRendering.name -crates/sqlbuild-python/src/bindings/_helpers/frontier/encoder.rs ColumnContractMode.name crates/sqlbuild-python/src/bindings/_helpers/frontier/encoder.rs ColumnLineageConfidence.name crates/sqlbuild-python/src/bindings/_helpers/frontier/encoder.rs ColumnTransformKind.name crates/sqlbuild-python/src/bindings/_helpers/frontier/encoder.rs CompiledResourceType.name diff --git a/tests/unit/src/sqlbuild/cli/commands/main/compile/_test_types.py b/tests/unit/src/sqlbuild/cli/commands/main/compile/_test_types.py index 233a5308e1..4576bc5f79 100644 --- a/tests/unit/src/sqlbuild/cli/commands/main/compile/_test_types.py +++ b/tests/unit/src/sqlbuild/cli/commands/main/compile/_test_types.py @@ -38,9 +38,11 @@ class CompileCommandTestCase: @dataclass(frozen=True) class CompileColumnContractModeTestCase: description: str - mode: str + settings_toml: str expected_audit_name: str expected_column_name: str + expected_stderr_fragment: str + expected_stderr_count: int @dataclass(frozen=True) diff --git a/tests/unit/src/sqlbuild/cli/commands/main/compile/test_compile_command.py b/tests/unit/src/sqlbuild/cli/commands/main/compile/test_compile_command.py index a20253d691..214b5f7956 100644 --- a/tests/unit/src/sqlbuild/cli/commands/main/compile/test_compile_command.py +++ b/tests/unit/src/sqlbuild/cli/commands/main/compile/test_compile_command.py @@ -247,8 +247,8 @@ def test_given_python_project_dag_flag_when_running_compile_then_writes_python_d " --> models/orders.sql:5:5", " 5 | customer_id (),", " | ^^^^^^^^^^^", - 'settings.column_contract_mode is "implicit" (the default)', - 'column_contract_mode = "explicit"', + "settings.check_declared_columns is true (the default)", + "check_declared_columns = false", "models with contract enforced remain validated", "\u2717 Project compiled 1 model, 0 seeds, 0 functions, 1 error, 0 warnings", " Wrote: target/compiled/", @@ -420,24 +420,38 @@ def test_given_contract_errors_when_running_compile_json_then_serializes_diagnos "test_case", [ CompileColumnContractModeTestCase( - description="explicit mode retains column audit", - mode="explicit", + description="unchecked declared columns retain column audit", + settings_toml="check_declared_columns = false", expected_audit_name="not_null", expected_column_name="customer_id", - ) + expected_stderr_fragment="deprecated", + expected_stderr_count=0, + ), + CompileColumnContractModeTestCase( + description="deprecated explicit mode warns and retains column audit", + settings_toml='column_contract_mode = "explicit"', + expected_audit_name="not_null", + expected_column_name="customer_id", + expected_stderr_fragment=( + "Warning: settings.column_contract_mode in sqlbuild_project.toml is deprecated; " + "replace it with settings.check_declared_columns = false" + ), + expected_stderr_count=1, + ), ], ids=lambda case: case.description, ) -def test_given_explicit_column_contract_mode_when_compiling_column_audit_then_audit_is_retained_without_contract_error( +def test_given_unchecked_declared_columns_when_compiling_column_audit_then_audit_is_retained_without_contract_error( test_case: CompileColumnContractModeTestCase, tmp_path: Path, monkeypatch: pytest.MonkeyPatch, + capsys: pytest.CaptureFixture[str], ) -> None: project_dir: Path = prepare_static_compile_project(tmp_path) project_config_path: Path = project_dir / "sqlbuild_project.toml" project_config_path.write_text( project_config_path.read_text(encoding="utf-8") - + f'\n[settings]\ncolumn_contract_mode = "{test_case.mode}"\n', + + f"\n[settings]\n{test_case.settings_toml}\n", encoding="utf-8", ) (project_dir / "models" / "orders.sql").write_text( @@ -467,6 +481,8 @@ def test_given_explicit_column_contract_mode_when_compiling_column_audit_then_au assert len(dag_payload["checks"]) == 1 assert dag_payload["checks"][0]["name"] == test_case.expected_audit_name assert dag_payload["checks"][0]["attached_column_name"] == test_case.expected_column_name + stderr: str = capsys.readouterr().err + assert stderr.count(test_case.expected_stderr_fragment) == test_case.expected_stderr_count @pytest.mark.parametrize( diff --git a/tests/unit/src/sqlbuild/compiler/contracts/_test_types.py b/tests/unit/src/sqlbuild/compiler/contracts/_test_types.py index 8f5b20ce8c..3f53c948d6 100644 --- a/tests/unit/src/sqlbuild/compiler/contracts/_test_types.py +++ b/tests/unit/src/sqlbuild/compiler/contracts/_test_types.py @@ -16,7 +16,7 @@ class ContractValidationTestCase: expected_severities: tuple[str, ...] expected_messages: tuple[str, ...] contract: str | None = None - column_contract_mode: str = "implicit" + check_declared_columns: bool = True not_null_audit_columns: tuple[str, ...] = () declared_nullable_by_column: dict[str, bool | None] | None = None inferred_nullability_by_column: dict[str, InferredNullability] | None = None diff --git a/tests/unit/src/sqlbuild/compiler/contracts/helpers.py b/tests/unit/src/sqlbuild/compiler/contracts/helpers.py index 2f9e482c04..d968d3cf38 100644 --- a/tests/unit/src/sqlbuild/compiler/contracts/helpers.py +++ b/tests/unit/src/sqlbuild/compiler/contracts/helpers.py @@ -4,7 +4,6 @@ from typing import cast from sqlbuild._native import ( - ColumnContractMode, CompiledModel, CompiledObjectKey, CompiledProject, @@ -30,7 +29,7 @@ def make_contract_project( inferred_columns: tuple[tuple[str, str | None], ...] | None, type_enforcement: bool | None, contract: str | None = None, - column_contract_mode: str = "implicit", + check_declared_columns: bool = True, model_name: str = "orders", column_locations: dict[str, SourceLocation] | None = None, not_null_audit_columns: tuple[str, ...] = (), @@ -52,7 +51,7 @@ def make_contract_project( effective_target_name="dev", effective_connection={}, effective_vars={}, - settings=SettingsConfig(column_contract_mode=ColumnContractMode(column_contract_mode)), + settings=SettingsConfig(check_declared_columns=check_declared_columns), models=( CompiledModel( key=key, diff --git a/tests/unit/src/sqlbuild/compiler/contracts/test_validate.py b/tests/unit/src/sqlbuild/compiler/contracts/test_validate.py index 02e284d25b..7a67065018 100644 --- a/tests/unit/src/sqlbuild/compiler/contracts/test_validate.py +++ b/tests/unit/src/sqlbuild/compiler/contracts/test_validate.py @@ -52,7 +52,7 @@ declared_columns=(("customer_id", None),), inferred_columns=(("order_id", None),), type_enforcement=None, - column_contract_mode="explicit", + check_declared_columns=False, expected_codes=(), expected_severities=(), expected_messages=(), @@ -73,7 +73,7 @@ inferred_columns=(), type_enforcement=None, contract="enforced", - column_contract_mode="explicit", + check_declared_columns=False, expected_codes=("K001",), expected_severities=("error",), expected_messages=( @@ -87,7 +87,7 @@ inferred_columns=(), type_enforcement=None, contract="enforced", - column_contract_mode="explicit", + check_declared_columns=False, fast_lineage_has_star=True, expected_codes=(), expected_severities=(), @@ -98,7 +98,7 @@ declared_columns=(("amount_cents", "INTEGER"),), inferred_columns=(("amount_cents", "VARCHAR"),), type_enforcement=True, - column_contract_mode="explicit", + check_declared_columns=False, expected_codes=("K002",), expected_severities=("error",), expected_messages=( @@ -271,7 +271,7 @@ def test_given_compiled_project_when_validating_contracts_then_returns_expected_ inferred_nullability_by_column=test_case.inferred_nullability_by_column, fast_lineage_has_star=test_case.fast_lineage_has_star, contract=test_case.contract, - column_contract_mode=test_case.column_contract_mode, + check_declared_columns=test_case.check_declared_columns, ), dialect=TypeDialect.DUCKDB, ) diff --git a/tests/unit/src/sqlbuild/compiler/discovery/_helpers/_test_types.py b/tests/unit/src/sqlbuild/compiler/discovery/_helpers/_test_types.py index 5a48424c59..b08af6b5af 100644 --- a/tests/unit/src/sqlbuild/compiler/discovery/_helpers/_test_types.py +++ b/tests/unit/src/sqlbuild/compiler/discovery/_helpers/_test_types.py @@ -141,14 +141,14 @@ class EffectiveBatchDefaultTestCase: @dataclass(frozen=True) -class ColumnContractModeConfigTestCase: +class CheckDeclaredColumnsConfigTestCase: description: str settings_toml: str - expected_mode: str + expected_checked: bool @dataclass(frozen=True) -class ColumnContractModeConfigErrorTestCase: +class CheckDeclaredColumnsConfigErrorTestCase: description: str settings_toml: str expected_error_fragment: str diff --git a/tests/unit/src/sqlbuild/compiler/discovery/_helpers/test_yml_project.py b/tests/unit/src/sqlbuild/compiler/discovery/_helpers/test_yml_project.py index 81809b20ff..a6052229f4 100644 --- a/tests/unit/src/sqlbuild/compiler/discovery/_helpers/test_yml_project.py +++ b/tests/unit/src/sqlbuild/compiler/discovery/_helpers/test_yml_project.py @@ -19,8 +19,8 @@ ) from sqlbuild.runtime.event_exporting.types import LifecycleEventKind from tests.unit.src.sqlbuild.compiler.discovery._helpers._test_types import ( - ColumnContractModeConfigErrorTestCase, - ColumnContractModeConfigTestCase, + CheckDeclaredColumnsConfigErrorTestCase, + CheckDeclaredColumnsConfigTestCase, DeepProjectConnectionTestCase, DiffConfigTestCase, EffectiveBatchDefaultTestCase, @@ -2039,15 +2039,21 @@ def test_given_legacy_local_config_file_when_loading_local_config_then_it_raises @pytest.mark.parametrize( "test_case", [ - ColumnContractModeConfigTestCase("omitted mode uses implicit default", "", "implicit"), - ColumnContractModeConfigTestCase( - "explicit mode is accepted", 'column_contract_mode = "explicit"', "explicit" + CheckDeclaredColumnsConfigTestCase("omitted setting checks declared columns", "", True), + CheckDeclaredColumnsConfigTestCase( + "false leaves declared columns unchecked", "check_declared_columns = false", False + ), + CheckDeclaredColumnsConfigTestCase( + "deprecated implicit mode maps to true", 'column_contract_mode = "implicit"', True + ), + CheckDeclaredColumnsConfigTestCase( + "deprecated explicit mode maps to false", 'column_contract_mode = "explicit"', False ), ], ids=lambda case: case.description, ) -def test_given_column_contract_mode_when_loading_project_then_policy_is_typed( - test_case: ColumnContractModeConfigTestCase, tmp_path: Path +def test_given_check_declared_columns_when_loading_project_then_setting_is_a_bool( + test_case: CheckDeclaredColumnsConfigTestCase, tmp_path: Path ) -> None: (tmp_path / "sqlbuild_project.toml").write_text( f'name = "demo"\nadapter = "duckdb"\n[settings]\n{test_case.settings_toml}\n', @@ -2056,22 +2062,33 @@ def test_given_column_contract_mode_when_loading_project_then_policy_is_typed( config: ProjectConfig = load_project_config(project_dir=tmp_path) - assert config.settings.column_contract_mode == test_case.expected_mode + assert config.settings.check_declared_columns is test_case.expected_checked @pytest.mark.parametrize( "test_case", [ - ColumnContractModeConfigErrorTestCase( - "unsupported mode is rejected", + CheckDeclaredColumnsConfigErrorTestCase( + "unsupported deprecated mode is rejected", 'column_contract_mode = "disabled"', "settings.column_contract_mode must be one of: implicit, explicit", - ) + ), + CheckDeclaredColumnsConfigErrorTestCase( + "non-boolean value is rejected", + 'check_declared_columns = "yes"', + "check_declared_columns", + ), + CheckDeclaredColumnsConfigErrorTestCase( + "setting both keys is rejected", + 'check_declared_columns = true\ncolumn_contract_mode = "implicit"', + "settings cannot define both 'check_declared_columns' and deprecated " + "'column_contract_mode'", + ), ], ids=lambda case: case.description, ) -def test_given_invalid_column_contract_mode_when_loading_project_then_error_is_raised( - test_case: ColumnContractModeConfigErrorTestCase, tmp_path: Path +def test_given_invalid_check_declared_columns_when_loading_project_then_error_is_raised( + test_case: CheckDeclaredColumnsConfigErrorTestCase, tmp_path: Path ) -> None: (tmp_path / "sqlbuild_project.toml").write_text( f'name = "demo"\nadapter = "duckdb"\n[settings]\n{test_case.settings_toml}\n', diff --git a/website/src/content/docs/docs/cli/compile.mdx b/website/src/content/docs/docs/cli/compile.mdx index d96b256882..818480b327 100644 --- a/website/src/content/docs/docs/cli/compile.mdx +++ b/website/src/content/docs/docs/cli/compile.mdx @@ -146,7 +146,7 @@ error[K001]: declared column 'total_cents' was not found in statically inferred --> models/marts/fact_orders.sql:6:5 6 | total_cents (), | ^^^^^^^^^^^ - = help: add total_cents to the SELECT list or correct/remove MODEL(columns (...)); MODEL(columns (...)) is validated using static SQL analysis because settings.column_contract_mode is "implicit" (the default). If this project intentionally uses columns only for metadata and audits, set [settings] column_contract_mode = "explicit"; models with contract enforced remain validated + = help: add total_cents to the SELECT list or correct/remove MODEL(columns (...)); MODEL(columns (...)) is validated using static SQL analysis because settings.check_declared_columns is true (the default). If this project intentionally uses columns only for metadata and audits, set [settings] check_declared_columns = false; models with contract enforced remain validated ``` | Code | Meaning | @@ -156,16 +156,16 @@ error[K001]: declared column 'total_cents' was not found in statically inferred | `K003` | A column's type can't be proven (with `type_enforcement` on) | | `K013` | A string literal fills an enum-typed column of an enforced contract but isn't a member of the enum (not checked on SQL Server) | -Which models are checked depends on `[settings] column_contract_mode`: +Which models are checked depends on `[settings] check_declared_columns`: -- `implicit` (default): a model with declared columns and no `contract` setting must output every +- `true` (default): a model with declared columns and no `contract` setting must output every declared column. -- `explicit`: only models with `contract enforced` are shape-checked; declared columns elsewhere +- `false`: only models with `contract enforced` are shape-checked; declared columns elsewhere are metadata and audit targets. -Explicit type enforcement works in both modes. Switching to `explicit` is a project policy, not a +Explicit type enforcement works with either value. Setting `false` is a project policy, not a way to silence an error: if a model is meant to have a contract, fix the query or the -declaration. Errors on `contract enforced` models don't suggest changing the mode. See +declaration. Errors on `contract enforced` models don't suggest changing the setting. See [Contracts](/docs/concepts/models/contracts). ## Output diff --git a/website/src/content/docs/docs/concepts/models/contracts.mdx b/website/src/content/docs/docs/concepts/models/contracts.mdx index aefe17679d..7377be5034 100644 --- a/website/src/content/docs/docs/concepts/models/contracts.mdx +++ b/website/src/content/docs/docs/concepts/models/contracts.mdx @@ -3,22 +3,22 @@ title: "Contracts" description: "Validate required or exact model output schemas." --- -A model's declared columns provide output metadata, type enforcement, and column audit attachment. The project `column_contract_mode` and model `contract` policy determine whether those declarations also define a statically validated output shape. +A model's declared columns provide output metadata, type enforcement, and column audit attachment. The project `check_declared_columns` setting and model `contract` policy determine whether those declarations also define a statically validated output shape. | Model declaration | Behavior | |-------------------|----------| -| Unspecified | Follow `settings.column_contract_mode`: `implicit` validates declared columns as an open shape; `explicit` treats them as metadata and audit attachment only. | +| Unspecified | Follow `settings.check_declared_columns`: `true` validates declared columns as an open shape; `false` treats them as metadata and audit attachment only. | | `none` | Do not activate declared-shape or nullability contract validation for this model. Explicit type enforcement remains active. | | `enforced` | Treat declared columns as the complete authoritative output shape and enable runtime exact-schema checks on supported materializations. | -The project default is `column_contract_mode = "implicit"`, which preserves SQLBuild's original behavior. Projects that use column declarations primarily for metadata and audits, including migrations from dbt, can opt into explicit contracts: +The project default is `check_declared_columns = true`. Projects that use column declarations primarily for metadata and audits, including migrations from dbt, can turn the check off: ```toml [settings] -column_contract_mode = "explicit" +check_declared_columns = false ``` -Under explicit mode, a model must declare `contract enforced` to activate shape validation. A model-level `contract enforced` or `contract none` always overrides the project mode. +With `check_declared_columns = false`, a model must declare `contract enforced` to activate shape validation, the same as every other model declaring `contract none`. A model-level `contract enforced` or `contract none` always overrides the project setting. ```sql MODEL ( @@ -47,7 +47,7 @@ When declared-shape validation is active and SQL analysis can infer the model's If SQLBuild cannot infer the output shape, these static shape checks cannot run. An enforced contract additionally requires a non-empty column declaration and adds runtime requirements on supported materializations. -Type enforcement remains independent. Typed columns continue to receive static type checks and supported runtime casts under explicit mode and `contract none`. +Type enforcement remains independent. Typed columns continue to receive static type checks and supported runtime casts with `check_declared_columns = false` and `contract none`. Configuration fields that reference output columns, including `unique_key`, `cursor`, `updated_at`, and `check_columns`, are checked against an enforced declaration. @@ -156,6 +156,6 @@ non-projection uses such as `join_on`, `where`, `group_by`, and `window_order_by ## Related policies -The project default is implicit open-shape validation for models that omit `contract`. A repository can select explicit opt-in contracts with `settings.column_contract_mode = "explicit"` or configure a custom [Rule](/docs/concepts/rules/custom-rules/overview) that requires enforced contracts for selected model families. +The project default checks declared columns as an open shape for models that omit `contract`. A repository can require an explicit `contract enforced` instead with `settings.check_declared_columns = false` or configure a custom [Rule](/docs/concepts/rules/custom-rules/overview) that requires enforced contracts for selected model families. Contracts also constrain schema-change behavior. For example, `snapshot_schema_change append_new_columns` is incompatible with `contract enforced` because an unannounced appended column would violate the exact declaration. diff --git a/website/src/content/docs/docs/concepts/models/schemas.mdx b/website/src/content/docs/docs/concepts/models/schemas.mdx index e7b05a8d41..311a58cb9f 100644 --- a/website/src/content/docs/docs/concepts/models/schemas.mdx +++ b/website/src/content/docs/docs/concepts/models/schemas.mdx @@ -126,7 +126,7 @@ Physical SQL output order is not currently enforced. Static contract analysis ma ## Contracts and planning -`contract enforced` treats the complete named-plus-local declaration as the exact output shape. An unspecified model follows the project's `column_contract_mode`; `contract none` explicitly keeps the resolved columns as metadata, audit attachment, and type-enforcement inputs without activating shape validation. See [Contracts](/docs/concepts/models/contracts). +`contract enforced` treats the complete named-plus-local declaration as the exact output shape. An unspecified model follows the project's `check_declared_columns` setting; `contract none` explicitly keeps the resolved columns as metadata, audit attachment, and type-enforcement inputs without activating shape validation. See [Contracts](/docs/concepts/models/contracts). For models bound to a reusable schema, effective column names, types, nullability, and enum members participate in model version identity. Changing those fields on a parent therefore affects models bound through descendants. Descriptions do not change model identity. Audits have their own audit-gate identities, so audit changes invalidate reusable audit results without changing the model version itself. diff --git a/website/src/content/docs/docs/concepts/project-configuration.mdx b/website/src/content/docs/docs/concepts/project-configuration.mdx index e987399e32..32e5661fa1 100644 --- a/website/src/content/docs/docs/concepts/project-configuration.mdx +++ b/website/src/content/docs/docs/concepts/project-configuration.mdx @@ -628,7 +628,7 @@ Global feature toggles: sql_analysis = true require_sql_analysis = false query_change_tracking = true -column_contract_mode = "implicit" +check_declared_columns = true concurrency = 1 microbatch_concurrency = false auto_load_sources = true @@ -646,7 +646,7 @@ delta_compile = true | `sql_analysis` | `true` | Enable SQL syntax analysis, column binding, type inference, output inference, and semantic validation at compile time | | `require_sql_analysis` | `false` | Allow `sql_analysis false` (in a MODEL header or a `[path_defaults]` entry) only on models whose SQL the parser cannot read, and reject `[settings] sql_analysis = false` in `sqlbuild_local.toml`. Project file only. See [SQL analysis](/docs/concepts/models/configuration#sql-analysis). | | `query_change_tracking` | `true` | Track query fingerprints for change detection. A fingerprint covers the SQL tokens of the compiled query and ignores whitespace, comments, and the letter case of reserved keywords and built-in function names, so formatting-only edits do not rebuild. Every other word, including non-reserved keywords, identifiers, aliases, JSON path keys and user-defined function names, counts exactly, as do string literals, quoted identifiers, numbers, and optimizer hints. | -| `column_contract_mode` | `implicit` | Controls whether column declarations on models without a `contract` declaration activate static shape/nullability validation. `implicit` preserves that validation; `explicit` treats columns as metadata and audit attachment unless the model declares `contract enforced`. Model-level `contract enforced` and `contract none` override this setting. Explicit type enforcement remains independent. See [Contracts](/docs/concepts/models/contracts). | +| `check_declared_columns` | `true` | Controls whether column declarations on models without a `contract` declaration activate static shape/nullability validation. `true` checks that every declared column is in the SELECT and checks its nullability; `false` treats columns as metadata and audit attachment unless the model declares `contract enforced`. Model-level `contract enforced` and `contract none` override this setting. Explicit type enforcement remains independent. See [Contracts](/docs/concepts/models/contracts). | | `concurrency` | `1` | Default number of worker connections for commands that run resources in parallel, such as `sqb build`, `sqb test`, `sqb audit`, and `sqb seed`, and for `sqb janitor` actions on warehouses that run DDL concurrently; a target's `concurrency` and `--concurrency` override it (see [Target concurrency](#target-concurrency)) | | `microbatch_concurrency` | `false` | Explicitly permit models with `batch_concurrency > 1`; concurrent batches use immutable coordination facts | | `auto_load_sources` | `true` | Automatically run source loaders before building dependent models during `sqb build`. See [Loaders](/docs/concepts/python-nodes/loaders). |