Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from airflow.api_fastapi.logging.decorators import action_logging
from airflow.assets.manager import asset_manager
from airflow.configuration import conf
from airflow.exceptions import ParamValidationError
from airflow.models.asset import (
AssetAliasModel,
AssetDagRunQueue,
Expand Down Expand Up @@ -443,21 +444,24 @@ def materialize_asset(
f"Dag with dag_id: '{dag_id}' does not allow asset materialization runs",
)

params = (body or MaterializeAssetBody()).validate_context(dag)
return dag.create_dagrun(
run_id=params["run_id"],
logical_date=params["logical_date"],
data_interval=params["data_interval"],
run_after=params["run_after"],
conf=params["conf"],
run_type=DagRunType.ASSET_MATERIALIZATION,
triggered_by=DagRunTriggeredByType.REST_API,
triggering_user_name=user.get_name(),
state=DagRunState.QUEUED,
partition_key=params["partition_key"],
note=params["note"],
session=session,
)
try:
params = (body or MaterializeAssetBody()).validate_context(dag)
return dag.create_dagrun(
run_id=params["run_id"],
logical_date=params["logical_date"],
data_interval=params["data_interval"],
run_after=params["run_after"],
conf=params["conf"],
run_type=DagRunType.ASSET_MATERIALIZATION,
triggered_by=DagRunTriggeredByType.REST_API,
triggering_user_name=user.get_name(),
state=DagRunState.QUEUED,
partition_key=params["partition_key"],
note=params["note"],
session=session,
)
except (ParamValidationError, ValueError) as e:
raise HTTPException(status.HTTP_400_BAD_REQUEST, str(e)) from e


@assets_router.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,19 @@ def test_should_respond_403_when_user_cannot_trigger_dag(self, test_client):
user=mock.ANY,
)

@pytest.mark.usefixtures("configure_git_connection_for_dag_bundle")
def test_should_respond_400_on_invalid_dag_run_id(self, test_client):
"""A dag_run_id containing '..' triggers ValueError in DagRun.validate_run_id.

It must surface as 400 BAD_REQUEST, not 500 INTERNAL_SERVER_ERROR.
"""
response = test_client.post(
"/assets/1/materialize",
json={"dag_run_id": "bad..id"},
)
assert response.status_code == 400
assert "must not contain '..'" in response.json()["detail"]


class TestGetAssetQueuedEvents(TestQueuedEventEndpoint):
@pytest.mark.usefixtures("time_freezer")
Expand Down
Loading