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-81 Add Insert Multiple Pools API #44121

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

Conversation

jason810496
Copy link
Contributor

closes: #43896
related: #43657

Fix: Add max_length=256 for PoolPostBody.pool

The model defined in https://github.com/apache/airflow/blob/main/airflow/models/pool.py#L54 enforces a string length constraint on Pool.pool. To maintain consistency, this constraint should also be validated at the router level.

Refactor: Handle Duplicate Cases in Insert Pool

The Insert Pool (single insert) functionality should account for cases where a duplicate pool name is provided, as Pool.pool is defined with a unique constraint.

Feat: Add Insert Multiple Pools API

A new API endpoint for inserting multiple pools has been introduced as /pools/bulk. Alternative names such as /pools/batch or /pools/multiple were considered. Feedback on which name best describes the endpoint is welcome.

@boring-cyborg boring-cyborg bot added the area:UI Related to UI/UX. For Frontend Developers. label Nov 18, 2024
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 thanks

airflow/api_fastapi/core_api/routes/public/pools.py Outdated Show resolved Hide resolved
airflow/api_fastapi/core_api/datamodels/pools.py Outdated Show resolved Hide resolved
@jason810496 jason810496 force-pushed the feature/AIP-81/add-bulk-insert-pools-api branch from 9fa560e to 42e8a51 Compare November 18, 2024 12:53
@bugraoz93 bugraoz93 added the area:API Airflow's REST/HTTP API label Nov 19, 2024
@bugraoz93
Copy link
Collaborator

Looks good! Thanks for the changes @jason810496! I believe the CI failure is likely a transient error caused by a DNS issue that couldn’t resolve AWS S3 at that moment.

@Lee-W
Copy link
Member

Lee-W commented Nov 20, 2024

Looks good! Thanks for the changes @jason810496! I believe the CI failure is likely a transient error caused by a DNS issue that couldn’t resolve AWS S3 at that moment.

just reran. seems to work fine 👀

@jason810496 jason810496 force-pushed the feature/AIP-81/add-bulk-insert-pools-api branch from 42e8a51 to 1ec682f Compare November 20, 2024 12:20
@jason810496
Copy link
Contributor Author

Just resolved the issue with inserting duplicate pools by handling the database exception rather than adding extra logic to the datamodels or performing additional database queries.
By the way, I’m happy to work further on refactoring to handle duplicate insertion cases across all endpoints 🙌

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.

Looking good, one minor nit, we can merge then.

Comment on lines +71 to +77
response = test_client.post("/public/pools/", json=body)
assert response.status_code == expected_status_code

assert response.json() == expected_response
if check_count:
assert session.query(Pool).count() == n_pools + 1

Copy link
Member

@pierrejeambrun pierrejeambrun Nov 20, 2024

Choose a reason for hiding this comment

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

Maybe don't factorize this part. It looks like this is an Arrange function (sense of Arrange/Act/Assert), like others similar function in tests, to prepare some objects for the test. But then it actually is a 'full' test, with assertions etc...

We only re-use this at 2 places, we can leave that inlined, especially the code won't be exacly the same and simpler for the 409 case

pierrejeambrun
pierrejeambrun previously approved these changes Nov 20, 2024
@pierrejeambrun
Copy link
Member

By the way, I’m happy to work further on refactoring to handle duplicate insertion cases across all endpoints 🙌

That would be great. You can create an issue to track that if you're not going to work on it directly just so we do not forget about it. If you plan on tackling that right away, no need to create an issue opening a PR is perfectly fine.

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.

maybe this is not the best approach

Comment on lines +206 to +212
session.commit()
except IntegrityError as e:
session.rollback()
raise HTTPException(
status.HTTP_409_CONFLICT,
detail=f"One or more pools already exists. Error: {e}",
)
Copy link
Member

Choose a reason for hiding this comment

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

Actually I am second guessing this.

The session is already commited on request exit.

Maybe what we need is simply an additional exception handler for IngegrityError, global.

Because here the context manager will try to commit again an empty session on exiting the endpoint. Which is a little bit weird and unecessary. Also this would remove the need to try / commit/rollback manually.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like this:
https://fastapi.tiangolo.com/tutorial/handling-errors/#install-custom-exception-handlers

And we check that in the error there is Unique and then we return 409 response ?

So we can just remove all the try / catch / etc... specific code, and the double call to commit()

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AIP-81 Implement POST/Insert Multiple Pools in FastAPI
5 participants