Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIP-84 Migrate Trigger Dag Run endpoint to FastAPI #43875

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

rawwar
Copy link
Collaborator

@rawwar rawwar commented Nov 11, 2024

related to #42701

@boring-cyborg boring-cyborg bot added area:API Airflow's REST/HTTP API area:UI Related to UI/UX. For Frontend Developers. labels Nov 11, 2024
@rawwar rawwar force-pushed the kalyan/AIP-84/trigger_dag_run branch from b11977f to ed49619 Compare November 20, 2024 04:02
"""Trigger DAG Run Serializer for POST body."""

dag_run_id: str | None
logical_date: datetime
Copy link
Collaborator Author

@rawwar rawwar Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to legacy endpoint implementation, logical_date can't be None. So, I had to remove datetime| None.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to remove this entirely and let the backend interpret the logical_date. I assume that has to happen at a deeper layer than use fastapi is that right @uranusjr ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referred to the implementation and updated this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah a deeper layer should infer logical date from the data interval, or use now() if those are not provided. This should not take the argument at all.

Comment on lines 103 to 108

# Mypy issue https://github.com/python/mypy/issues/1362
@computed_field # type: ignore[misc]
@property
def _logical_date(self) -> datetime:
return self.logical_date or timezone.utcnow()
Copy link
Member

@pierrejeambrun pierrejeambrun Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following @uranusjr, we remove everything related to logical_date (if the db allows us to insert like this), and we will leave a deeper layer populate that for us. But then without a logical_date we need to manually create the dag_run_id for now.

@model_validator(mode="after")
def validate_dag_run_id(self):
if not self.dag_run_id:
self.dag_run_id = DagRun.generate_run_id(DagRunType.MANUAL, self.logical_date)
Copy link
Member

@pierrejeambrun pierrejeambrun Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uranusjr If we remove the logical_date, then we have None for logical date when creating the dagrun with create_dagrun, and unfortunately it needs type + logical_date to infer the run_id. This is why we need to manually fill the run_id here in case it's not there, but I am not a big fan of it. (is that ok ?)

I assume this will be updated later when the logical_date change will take place => create_dagrun will be able to generate an appropriate run_id without providing logical_date ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, Shall I just remove logical_date from request body and use current time by default to generate run_id? Once updated made to create_dagrun, this can also be updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's remove it from the request body.

@rawwar rawwar added the legacy api Whether legacy API changes should be allowed in PR label Nov 22, 2024
conf: dict = Field(default_factory=dict)
note: str | None = None

model_config = {"extra": "forbid"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it'll be great to keep this consistent across all APIs. Legacy API throws 400 bad request on extra properties passed, while since FastAPI and Pydantic ignore extra properties, new APIs don't throw an error yet.

We could either forbid extra properties for all models or for none of them, so the users have a consistent view of the APIs. In new APIs, I suppose currently forbidding is being done only in CreateAssetEventsBody here.

Copy link
Collaborator Author

@rawwar rawwar Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I created a draft to start a conversation on this: #44306

Forgot to link this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:API Airflow's REST/HTTP API area:UI Related to UI/UX. For Frontend Developers. legacy api Whether legacy API changes should be allowed in PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants