Source Nodes Rendering#

Note

This feature is only available for dbt-core >= 1.5 and cosmos >= 1.6.0.

By default, Cosmos does not render dbt sources automatically. Instead, you need to configure the rendering of sources explicitly. You can control this behavior using the source_rendering_behavior field in the RenderConfig object. This is how it works:

  • all: When set to all, Cosmos renders all sources in the dbt project. It uses three different node types for this:

    • EmptyOperator: For sources that do not have tests or freshness checks.

    • DbtSourceOperator: For sources that have freshness checks.

    • DbtTestOperator: For sources that have tests.

    This approach aims to create a comprehensive DAG that aligns with dbt documentation, allowing for the rendering of both sources and models for a more detailed visual representation. It also ensures that model dependencies do not run if their sources are not fresh, thus preventing the execution of stale or incomplete data.

  • none (default): When set to none, Cosmos does not automatically render any sources. Note that if node converters are being used for sources, they will still function as intended.

  • with_tests_or_freshness: When set to with_tests_or_freshness, Cosmos only renders sources that have either tests or freshness checks.

Example:

from cosmos import DbtTaskGroup, RenderConfig
from cosmos.constants import SourceRenderingBehavior

jaffle_shop = DbtTaskGroup(
    render_config=RenderConfig(
        source_rendering_behavior=SourceRenderingBehavior.WITH_TESTS_OR_FRESHNESS,
    )
)