Skip to content

Commit

Permalink
Merge branch 'master' into nikki/docs/hybrid-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
neverett committed Dec 18, 2024
2 parents 521dbc0 + dc690a6 commit 79c118e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions python_modules/dagster/dagster/_generate/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"feature_graph_backed_assets",
"getting_started_etl_tutorial",
"project_analytics",
"project_atproto_dashboard",
"project_dagster_modal_pipes",
"project_dagster_university_start",
"project_du_dbt_starter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@
import dagster._check as check
from dagster._record import record
from jinja2 import Template
from pydantic import BaseModel
from pydantic import BaseModel, Field
from pydantic.fields import FieldInfo

T = TypeVar("T")

REF_BASE = "#/$defs/"
REF_TEMPLATE = f"{REF_BASE}{{model}}"

CONTEXT_KEY = "required_rendering_context"
CONTEXT_KEY = "required_rendering_scope"


def add_required_rendering_context(field: Any, context: AbstractSet[str]) -> Any:
def RenderingScope(field: Optional[FieldInfo] = None, *, required_scope: AbstractSet[str]) -> Any:
"""Defines a Pydantic Field that requires a specific scope to be available before rendering.
Examples:
```python
class Schema(BaseModel):
a: str = RenderingScope(required_scope={"foo", "bar"})
b: Optional[int] = RenderingScope(Field(default=None), required_scope={"baz"})
```
"""
return FieldInfo.merge_field_infos(
field, FieldInfo(json_schema_extra={CONTEXT_KEY: json.dumps(list(context))})
field or Field(), Field(json_schema_extra={CONTEXT_KEY: json.dumps(list(required_scope))})
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
TemplatedValueResolver,
component,
)
from dagster_components.core.component_rendering import add_required_rendering_context
from dagster_components.core.component_rendering import RenderingScope
from dagster_components.core.dsl_schema import AssetSpecProcessorModel, OpSpecBaseModel
from dagster_components.generate import generate_component_yaml

Expand All @@ -32,8 +32,8 @@ class DbtNodeTranslatorParams(BaseModel):
class DbtProjectParams(BaseModel):
dbt: DbtCliResource
op: Optional[OpSpecBaseModel] = None
translator: Optional[DbtNodeTranslatorParams] = add_required_rendering_context(
Field(default=None), {"node"}
translator: Optional[DbtNodeTranslatorParams] = RenderingScope(
Field(default=None), required_scope={"node"}
)
asset_attributes: Optional[Sequence[AssetSpecProcessorModel]] = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,28 @@

import pytest
from dagster_components.core.component_rendering import (
RenderingScope,
TemplatedValueResolver,
_should_render,
add_required_rendering_context,
preprocess_value,
)
from pydantic import BaseModel, Field, TypeAdapter


class Inner(BaseModel):
a: Optional[str] = None
deferred: Optional[str] = add_required_rendering_context(
Field(default=None), {"foo", "bar", "baz"}
)
deferred: Optional[str] = RenderingScope(required_scope={"foo", "bar", "baz"})


class Outer(BaseModel):
a: str
deferred: str = add_required_rendering_context(Field(), {"a"})
deferred: str = RenderingScope(required_scope={"a"})
inner: Sequence[Inner]
inner_deferred: Sequence[Inner] = add_required_rendering_context(Field(), {"b"})
inner_deferred: Sequence[Inner] = RenderingScope(required_scope={"b"})

inner_optional: Optional[Sequence[Inner]] = None
inner_deferred_optional: Optional[Sequence[Inner]] = add_required_rendering_context(
Field(default=None), {"b"}
inner_deferred_optional: Optional[Sequence[Inner]] = RenderingScope(
Field(default=None), required_scope={"b"}
)


Expand Down

0 comments on commit 79c118e

Please sign in to comment.