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

Unified Bulk Patch Endpoint for Connections in Rest API (FastAPI) #45715

Conversation

bugraoz93
Copy link
Collaborator

@bugraoz93 bugraoz93 commented Jan 16, 2025

relates: #45601

  • Implementing the unified approach for bulk endpoints.

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@boring-cyborg boring-cyborg bot added the area:UI Related to UI/UX. For Frontend Developers. label Jan 16, 2025
@bugraoz93 bugraoz93 added the area:API Airflow's REST/HTTP API label Jan 16, 2025
@bugraoz93 bugraoz93 force-pushed the feat/45601/unified-bulk-connection-endpoint branch from 130e0de to 7bc8d43 Compare January 19, 2025 17:08
@bugraoz93 bugraoz93 marked this pull request as ready for review January 19, 2025 17:10
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

Nice

A few suggestions, and hint for follow up PRs. Almost ready to merge.

…e default for mutable fields and fix a comment, Remove unit test for old method
…ding to tests, include unit tests, Fix Session Add for Create Action
@bugraoz93 bugraoz93 force-pushed the feat/45601/unified-bulk-connection-endpoint branch from 7bc8d43 to 1bcfc03 Compare January 20, 2025 21:14
@bugraoz93
Copy link
Collaborator Author

bugraoz93 commented Jan 20, 2025

Nice

A few suggestions, and hint for follow up PRs. Almost ready to merge.

Thanks for the quick review! I updated the code according to the comments.

I agree with all the other comments and created an issue for it too #45816.
While making fields enums, I tried to create a baseline for unifying data models for bulk operations in general which could be applied for any unification for data models. I moved them in common.py. I have included TODO for further unification for datamodels from this story.

@pierrejeambrun
Copy link
Member

Nice

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

Thanks 🎉

@pierrejeambrun pierrejeambrun merged commit 995ec1e into apache:main Jan 22, 2025
45 checks passed
@potiuk
Copy link
Member

potiuk commented Jan 22, 2025

NIIIIICE!

@shubhamraj-git
Copy link
Contributor

shubhamraj-git commented Jan 22, 2025

Hey @bugraoz93 ,
we replaced action_if_exists and action_if_not_exists with action_on_existence

  1. This contains, "overwrite", which would be not relevant in case of delete and update, and will fail.
  2. Also, action_on_existence seems misleading in case of update and delete, since the operations here were for if the value is not present and not on existence, when either it fails or skip.
  3. [In context of Pools bulk API] Since the PoolBulkCreateAction and PoolBulkUpdateAction models share the same structure (both have an action field and a pools list), pydantic may incorrectly parse an update action as a create action because it matches the first type (PoolBulkCreateAction) in the union. This issue here is because the PoolBulkCreateAction and PoolBulkUpdateAction have pools type as different list[PoolPostBody] and list[PoolPatchBody] respectively. [Can refer the below attached PR]

Was this intentional? Or just a miss, in case I can rectify this in upcoming PR for bulk pool.

For now, based upon above comments, I have included that in #45939

@bugraoz93
Copy link
Collaborator Author

Hey @bugraoz93 , we replaced action_if_exists and action_if_not_exists with action_on_existence

  1. This contains, "overwrite", which would be not relevant in case of delete and update, and will fail.
  2. Also, action_on_existence seems misleading in case of update and delete, since the operations here were for if the value is not present and not on existence, when either it fails or skip.

Was this intentional? Or just a miss, in case I can rectify this in upcoming PR for bulk pool.

Hey @shubhamraj-git ,
This was the baseline for making things common for the bulk endpoints so implementation is still from surface at the moment. I think things are getting clearer while we implement more use cases/endpoints.

On the documentation perspective overwrite is not relevant and it could be a side effect/bug since we are allowing to call the endpoints with overwrite in this case. I think we can drive from a parent enum class to make documentation nice and separate the enum classes according to action types.

I am planning to do more unification for the datamodels in #45816. I can cover this one over there, it seems relevant. Please bring up anything in that issue to discuss more. Thanks for pointing out! I would be happy to bounce ideas and am going to tag you in the next PR.

@shubhamraj-git
Copy link
Contributor

Thanks @bugraoz93 , Sounds great.

For now, I have solved the bug by removing the action_on_existence from BaseModel, and included that differently for create and (delete & update). This solves all the three issues. This can be later unified when you are working on #45816 . Let me know if you need to do this in other way.

Also, I did this since the Pool Bulk PR #45939 is ready, and this seems to be earliest solution, didn't brainstorm more, since you are already working on #45816 which will anyways refactor these all.

@bugraoz93
Copy link
Collaborator Author

For now, based upon above comments, I have included that in #45939

I just saw this update after sending my message :) Feel free to change that part in your MR, I don't want to block you on that. Thanks!

For now, I have solved the bug by removing the action_on_existence from BaseModel, and included that differently for create and (delete & update). This solves all the three issues. This can be later unified when you are working on #45816 . Let me know if you need to do this in other way.

Also, I did this since the Pool Bulk PR #45939 is ready, and this seems to be earliest solution, didn't brainstorm more, since you are already working on #45816 which will anyways refactor these all.

Amazing, thanks! Looks good! I agree, fixing is enough and no need for brainstorming. I was trying to not put the work on you (mostly updating tests since they are unified now) :) I can move from there.

@pierrejeambrun
Copy link
Member

Nice guys, thanks for highlighting that @shubhamraj-git. Indeed that's a big part and the implementation is a little bit rough but i'm sure we will improve it iteratively. (sounds like we have a plan for that, I'll gladly review any PR on the front 😄)

@pierrejeambrun pierrejeambrun added the AIP-84 Modern Rest API label Jan 23, 2025
dauinh pushed a commit to dauinh/airflow that referenced this pull request Jan 24, 2025
…ache#45715)

* Initial implementation of Bulk Patch approach for Connections, replace default for mutable fields and fix a comment, Remove unit test for old method

* Comment update,Remove key from model_dump, Update Service logic according to tests, include unit tests, Fix Session Add for Create Action

* Remove unused print statement, unify bulk action types as enums and move them to common.py under datamodels
@utkarsharma2 utkarsharma2 added the type:new-feature Changelog: New Features label Jan 27, 2025
@utkarsharma2 utkarsharma2 added this to the Airflow 3.0.0 milestone Jan 27, 2025
gpathak128 pushed a commit to gpathak128/airflow that referenced this pull request Jan 29, 2025
…ache#45715)

* Initial implementation of Bulk Patch approach for Connections, replace default for mutable fields and fix a comment, Remove unit test for old method

* Comment update,Remove key from model_dump, Update Service logic according to tests, include unit tests, Fix Session Add for Create Action

* Remove unused print statement, unify bulk action types as enums and move them to common.py under datamodels
got686-yandex pushed a commit to got686-yandex/airflow that referenced this pull request Jan 30, 2025
…ache#45715)

* Initial implementation of Bulk Patch approach for Connections, replace default for mutable fields and fix a comment, Remove unit test for old method

* Comment update,Remove key from model_dump, Update Service logic according to tests, include unit tests, Fix Session Add for Create Action

* Remove unused print statement, unify bulk action types as enums and move them to common.py under datamodels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AIP-84 Modern Rest API area:API Airflow's REST/HTTP API area:UI Related to UI/UX. For Frontend Developers. type:new-feature Changelog: New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants