Feat/check multi team enabled when team name provided api#63994
Conversation
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
Outdated
Show resolved
Hide resolved
bugraoz93
left a comment
There was a problem hiding this comment.
Looks good, mine is also nit but I think both are relatively quick changes :)
airflow-core/src/airflow/api_fastapi/core_api/datamodels/variables.py
Outdated
Show resolved
Hide resolved
|
Thanks for the feedback. Currently debugging an issue with connections with this change. I believe some code is missing in the connections code that causes errors in the CI and when creating connections with this change, so will push code to address the comments what I fix that issue. |
|
@ahilashsasidharan are you working on it? |
@vincbeck yes sorry for the delay on this. I am moving these checks to Edit: Issue I mentioned was an environment issue I resolved. The CI issue should just be some missing code in the I am working on testing these changes manually to see if there are any other issues and if not will hopefully have something pushed soon. |
airflow-core/src/airflow/api_fastapi/core_api/datamodels/variables.py
Outdated
Show resolved
Hide resolved
pierrejeambrun
left a comment
There was a problem hiding this comment.
LGTM beside vincent comment.
Also it appears that CI need some fixing.
792cec8 to
4dd507c
Compare
|
I have rebase the branch to get the latest CI fixes from main. That could help with unrelated failures. |
|
Seems one test left reliably failing @ahilashsasidharan can you have a look? |
There was a problem hiding this comment.
Pull request overview
Adds request-body validation to prevent setting team_name when Airflow core.multi_team is disabled, and updates/extends unit tests to cover the new 422 behavior across Pools, Connections, and Variables APIs.
Changes:
- Added Pydantic
model_validatorchecks in Pools/Connections/Variables request body models. - Added/updated FastAPI unit tests to assert 422 responses when
team_nameis provided but multi-team is disabled. - Adjusted existing tests to explicitly enable multi-team where required for
team_name-bearing requests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| airflow-core/src/airflow/api_fastapi/core_api/datamodels/variables.py | Adds multi-team gating validator for team_name in Variable bodies. |
| airflow-core/src/airflow/api_fastapi/core_api/datamodels/pools.py | Adds multi-team gating validators for pool POST/PATCH bodies. |
| airflow-core/src/airflow/api_fastapi/core_api/datamodels/connections.py | Adds multi-team gating validator for connection bodies. |
| airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_variables.py | Adds tests asserting 422 when team_name is used with multi-team disabled. |
| airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_pools.py | Adds tests for 422 behavior and enables multi-team in existing tests that use team_name. |
| airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py | Adds tests for 422 behavior and enables multi-team in existing tests that use team_name. |
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_pools.py
Outdated
Show resolved
Hide resolved
4dd507c to
14d7e4e
Compare
airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/pools.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/pools.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
Outdated
Show resolved
Hide resolved
14d7e4e to
1197934
Compare
One thing to add for this is that having these checks gives us more control over how errors are sent for Bulk endpoints. Right now the implemenation for errors looks like this:
This would be how an error would like with the check being in datamodels with a model_validator (with more failing actions/entities):
Both reject the entire request even ones without team_name. That could be changed in public/routes implemenation. I've left some comments unresolved that are related to the other implemenation and will resolve them once I have some feedback on the preferred implementation. |
airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/pools.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/pools.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
Outdated
Show resolved
Hide resolved
1197934 to
230a1ad
Compare
airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
Outdated
Show resolved
Hide resolved
pierrejeambrun
left a comment
There was a problem hiding this comment.
Why did we move from having this validation done at the pydantic level (which I think was nice, part of the deserializer model) to now have this entangled in the router code?
I was debugging an issue with the pydantic implementation and switched to having it in the router code, but the issue was unrelated to either implementation. I was just waiting on feedback on the preferred method. If the pydantic method was nice. I will revert back to that as that implementation requires less code and complexity. |
airflow-core/src/airflow/api_fastapi/core_api/routes/public/pools.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py
Outdated
Show resolved
Hide resolved
… variables test file
230a1ad to
0659255
Compare
…#63994) * Add API check to ensure multi team is enabled when team_name is provided * remove unnecessary arguments in added tests * add variable tests and add slight change to other tests to align with variables test file * Change error message, Modify tests, Add bulk tests, Fix CI issues (cherry picked from commit 6271189) Co-authored-by: ahilashsasidharan <79016853+ahilashsasidharan@users.noreply.github.com>
Backport successfully created: v3-2-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…apache#63994) * Add API check to ensure multi team is enabled when team_name is provided * remove unnecessary arguments in added tests * add variable tests and add slight change to other tests to align with variables test file * Change error message, Modify tests, Add bulk tests, Fix CI issues (cherry picked from commit 6271189) Co-authored-by: ahilashsasidharan <79016853+ahilashsasidharan@users.noreply.github.com>

Description
This PR adds pydantic validators to the Pools, Connections and Variables APIs to ensure that multi_team mode is enabled when team_name is provided. This check is missing from these APIs.
Motivation
In the case of the Pools API (which should apply to other APIs) without this check as shown in issue #62251 under Test 3 you are able to create a pool when multi-team is disabled if there is a pre-existing team in the database, and if you try to add a pool with a non-existent team you will get a 500 error. With this change you will now get a 422 value error as shown below with a clearer error.
Tests
related: #62251
Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.