Generators
Classes
|
A part of a contract meant to generate a property for a resource based on its related database object. |
|
A part of a contract meant to generate properties for a resource based on its related database object. |
|
|
|
- class dbt_contracts.contracts.generators.PropertyGenerator(*, overwrite: bool = True)
Bases:
ContractPart,GenericA part of a contract meant to generate a property for a resource based on its related database object.
May also process an item while also taking into account its parent item e.g. a Column (child item) within a Model (parent item)
- abstractmethod run(source: S, target: T) bool
Run this generator on the given source, merging properties from the target item.
- Parameters:
source – The item to modify.
target – The item containing the target properties to set onto the source.
- Returns:
Boolean for if the source was modified.
- overwrite: bool
- class dbt_contracts.contracts.generators.PropertiesGenerator(*, exclude: Annotated[Sequence[str], BeforeValidator(func=to_tuple, json_schema_input_type=PydanticUndefined)] = ())
Bases:
ContractPart,GenericA part of a contract meant to generate properties for a resource based on its related database object.
May also process an item while also taking into account its parent item e.g. a Column (child item) within a Model (parent item)
- property generators: list[PropertyGenerator]
Get all the single property generators set on this generator, excluding those that are configured to be excluded.
- abstractmethod merge(item: I, context: ContractContext) bool
Merge the properties of the given item with the properties of its remote database object.
- Parameters:
item – The item to modify properties for.
context – The contract context to use.
- Returns:
Whether the properties of the item were modified.
- exclude: Annotated[Sequence[str], BeforeValidator(to_tuple)]
- class dbt_contracts.contracts.generators.ParentPropertiesGenerator(*, exclude: Annotated[Sequence[str], BeforeValidator(func=to_tuple, json_schema_input_type=PydanticUndefined)] = (), filename: str = '_config.yml', depth: Annotated[int | None, Ge(ge=0)] = None)
Bases:
PropertiesGenerator,Generic- generate_properties_path(item: I) Path
Generate a new properties path to use for the given item.
- model_post_init(context: Any, /) None
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Args:
self: The BaseModel instance. context: The context.
- update(item: I, context: ContractContext) dict[str, Any]
Update/generate the properties of the given item as a properties file.
If the item already has a properties path configured, properties will be updated in-place. Otherwise, a new properties file will be generated based on the configuration of this generator. This new properties file will be added to the context’s properties store. The path for this new properties file will be added to the item’s attributes.
- Parameters:
item – The item to update properties for.
context – The contract context to use.
- Returns:
The updated properties.
- filename: str
- depth: int | None
- class dbt_contracts.contracts.generators.ChildPropertiesGenerator(*, exclude: Annotated[Sequence[str], BeforeValidator(func=to_tuple, json_schema_input_type=PydanticUndefined)] = ())
Bases:
PropertiesGenerator,Generic- abstractmethod merge(item: I, context: ContractContext, parent: P = None) bool
Merge the properties of the given item with the properties of its remote database object.
- Parameters:
item – The item to modify properties for.
context – The contract context to use.
parent – The parent item that the given child
itembelongs to if available.
- Returns:
Whether the properties of the item were modified.
Modules