Node

Inheritance diagram of dbt_contracts.contracts.terms.node.Exists, dbt_contracts.contracts.terms.node.HasAllColumns, dbt_contracts.contracts.terms.node.HasContract, dbt_contracts.contracts.terms.node.HasExpectedColumns, dbt_contracts.contracts.terms.node.HasMatchingDescription, dbt_contracts.contracts.terms.node.HasNoFinalSemicolon, dbt_contracts.contracts.terms.node.HasNoHardcodedRefs, dbt_contracts.contracts.terms.node.HasTests, dbt_contracts.contracts.terms.node.HasValidMacroDependencies, dbt_contracts.contracts.terms.node.HasValidRefDependencies, dbt_contracts.contracts.terms.node.HasValidSourceDependencies, dbt_contracts.contracts.terms.node.HasValidUpstreamDependencies, dbt_contracts.contracts.terms.node.NodeContractTerm

Classes

Exists()

Check whether the {kind} exist in the database.

HasAllColumns()

Check whether {kind} have all columns set in their properties.

HasContract()

Check whether {kind} have appropriate configuration for a contract in their properties.

HasExpectedColumns(*[,Β columns])

Check whether {kind} have the expected names of columns set in their properties.

HasMatchingDescription(*[,Β ...])

Check whether the descriptions configured in {kind}' properties match the descriptions in the database.

HasNoFinalSemicolon()

Check if {kind} have a final semicolon present in their queries.

HasNoHardcodedRefs()

Check if {kind} have any hardcoded references to database objects in their queries.

HasTests(*[,Β min_count,Β max_count])

Check whether {kind} have an appropriate number of tests configured.

HasValidMacroDependencies()

Check whether {kind} have an appropriate number of upstream dependencies for macros i.e. the number of custom macros present in the query.

HasValidRefDependencies()

Check whether {kind} have an appropriate number of upstream dependencies i.e. the number of ref macros present in the query.

HasValidSourceDependencies()

Check whether {kind} have an appropriate number of upstream dependencies for sources i.e. the number of source macros present in the query.

HasValidUpstreamDependencies()

NodeContractTerm()

class dbt_contracts.contracts.terms.node.NodeContractTerm

Bases: ParentContractTerm, Generic

class dbt_contracts.contracts.terms.node.Exists

Bases: NodeContractTerm, Generic

Check whether the {kind} exist in the database.

needs_catalog: ClassVar[bool] = True

Mark if this term requires a loaded catalog to operate. The catalog must then be provided by the ContractContext for the term to execute successfully.

run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasTests(*, min_count: Annotated[int, Ge(ge=1)] = 1, max_count: Annotated[int | None, Gt(gt=0)] = None)

Bases: NodeContractTerm, RangeMatcher, Generic

Check whether {kind} have an appropriate number of tests configured.

needs_manifest: ClassVar[bool] = True

Mark if this term requires a loaded manifest to operate. The manifest must then be provided by the ContractContext for the term to execute successfully.

run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasAllColumns

Bases: NodeContractTerm, Generic

Check whether {kind} have all columns set in their properties. Ensures that all columns present in the database are present in dbt project properties.

needs_catalog: ClassVar[bool] = True

Mark if this term requires a loaded catalog to operate. The catalog must then be provided by the ContractContext for the term to execute successfully.

run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasExpectedColumns(*, columns: str | Sequence[str] | Mapping[str, str] = ())

Bases: NodeContractTerm, Generic

Check whether {kind} have the expected names of columns set in their properties. Also checks if those columns have the expected data types if configured to do so.

columns: str | Sequence[str] | Mapping[str, str]
run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasMatchingDescription(*, ignore_whitespace: bool = False, case_insensitive: bool = False, compare_start_only: bool = False)

Bases: NodeContractTerm, StringMatcher, Generic

Check whether the descriptions configured in {kind}’ properties match the descriptions in the database.

needs_catalog: ClassVar[bool] = True

Mark if this term requires a loaded catalog to operate. The catalog must then be provided by the ContractContext for the term to execute successfully.

run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasContract

Bases: NodeContractTerm, Generic

Check whether {kind} have appropriate configuration for a contract in their properties.

run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasValidUpstreamDependencies

Bases: NodeContractTerm, Generic

needs_manifest: ClassVar[bool] = True

Mark if this term requires a loaded manifest to operate. The manifest must then be provided by the ContractContext for the term to execute successfully.

class dbt_contracts.contracts.terms.node.HasValidRefDependencies

Bases: HasValidUpstreamDependencies, Generic

Check whether {kind} have an appropriate number of upstream dependencies i.e. the number of ref macros present in the query.

run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasValidSourceDependencies

Bases: HasValidUpstreamDependencies, Generic

Check whether {kind} have an appropriate number of upstream dependencies for sources i.e. the number of source macros present in the query.

run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasValidMacroDependencies

Bases: HasValidUpstreamDependencies, Generic

Check whether {kind} have an appropriate number of upstream dependencies for macros i.e. the number of custom macros present in the query.

run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasNoFinalSemicolon

Bases: NodeContractTerm, Generic

Check if {kind} have a final semicolon present in their queries.

run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.

class dbt_contracts.contracts.terms.node.HasNoHardcodedRefs

Bases: NodeContractTerm, Generic

Check if {kind} have any hardcoded references to database objects in their queries.

comments_pattern: ClassVar[str] = '(?<=(\\/\\*|\\{#))((.|[\\r\\n])+?)(?=(\\*+\\/|#\\}))|[ \\t]*--.*'
cte_keywords: ClassVar[frozenset[str]] = frozenset({'with'})
cte_pattern: ClassVar[str] = '^[\\w\\d_-]+$'
ref_keywords: ClassVar[frozenset[str]] = frozenset({'from', 'join'})
ref_ignore: ClassVar[frozenset[str]] = frozenset({'values'})
run(item: ItemT, context: ContractContext, parent: ParentT = None) → bool

Validate the context before running the term.