Skip to content

Conversation

@jason810496
Copy link
Member

related: #52860

Why

  • While working on Remove gunicorn daemonize for api-server #52860, I found that current api-server only respect --apps flag with --dev mode.
    • We use AIRFLOW_API_APPS environment to specify which apps are going to initialize in create_app call.
  • Also the AIRFLOW_API_APPS env is no restored properly, we should set back to original value if it's set before the airlow api-server run.

What

  • Add with_api_apps_env decorator with proper teardown
  • Refactor test_api_apps_env test with more scenario including all apps currently available, dev mode or not, and original env is set or not.

@jason810496 jason810496 added area:CLI area:API Airflow's REST/HTTP API labels Jul 6, 2025
@jason810496 jason810496 self-assigned this Jul 6, 2025
@jason810496 jason810496 requested review from Copilot, jedcunningham, kaxil, pierrejeambrun and potiuk and removed request for jedcunningham and kaxil July 6, 2025 04:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures the --apps flag is respected outside of dev mode and that the AIRFLOW_API_APPS environment variable is always restored to its original value.

  • Introduces a with_api_apps_env decorator to manage setting/tearing down the env var
  • Refactors api_server to use the decorator and removes inline env manipulation
  • Updates test_api_server_command.py to parameterize scenarios for dev/non-dev modes and original env states

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
airflow-core/tests/unit/cli/commands/test_api_server_command.py Parameterize and expand test_api_apps_env to cover all flag permutations and teardown
airflow-core/src/airflow/cli/commands/api_server_command.py Add with_api_apps_env decorator, apply to api_server, remove manual env handling, update type ignore on access_log
Comments suppressed due to low confidence (1)

airflow-core/tests/unit/cli/commands/test_api_server_command.py:121

  • [nitpick] The test verifies that AIRFLOW_API_APPS is cleaned up, but doesn’t assert that it was initially set to the expected value. Consider adding an assert on mock_environ.__setitem__ for the first assignment.
            api_server_command.api_server(parsed_args)

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

I am not sure how much we want to configure apps in prod - I guess we might find it useful in some deployments. But should not we describe it in documentation why to do it and how to do it?

@kaxil
Copy link
Member

kaxil commented Jul 6, 2025

I am not sure how much we want to configure apps in prod - I guess we might find it useful in some deployments. But should not we describe it in documentation why to do it and how to do it?

#43103 . Feel free to take it over @jason810496

@jason810496
Copy link
Member Author

I am not sure how much we want to configure apps in prod - I guess we might find it useful in some deployments.

IMO, it might be useful for scaling API server for Task Execution and Core API separately or for users that just need to run Task Execution API-server solely.

But should not we describe it in documentation why to do it and how to do it?
#43103 . Feel free to take it over @jason810496

Thanks for bringing up the related issue! I will raise another for the documentation side.
This PR is more like fixing the behavior for the --apps only.

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.

Yes this is useful for people that want to deploy a standalone execution api server. (Scaling, isolation etc.)

@jason810496 jason810496 force-pushed the fix/api-server/api-apps-env-setup-teardown branch from 874657d to 900003b Compare July 7, 2025 17:46
@kaxil kaxil added this to the Airflow 3.0.4 milestone Jul 7, 2025
@jason810496 jason810496 added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Jul 8, 2025
@jason810496 jason810496 force-pushed the fix/api-server/api-apps-env-setup-teardown branch 2 times, most recently from a41c768 to 824b711 Compare July 10, 2025 07:08
@jason810496 jason810496 force-pushed the fix/api-server/api-apps-env-setup-teardown branch from 824b711 to 19d8a8a Compare July 14, 2025 02:16
@jason810496 jason810496 merged commit c0c41ff into apache:main Jul 14, 2025
57 checks passed
@github-actions
Copy link

Backport failed to create: v3-0-test. View the failure log Run details

Status Branch Result
v3-0-test Commit Link

You can attempt to backport this manually by running:

cherry_picker c0c41ff v3-0-test

This should apply the commit to the v3-0-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

prdai pushed a commit to prdai/airflow that referenced this pull request Jul 15, 2025
* Respect apps flags for api_server_command

* Refactor test_api_apps_env
@pierrejeambrun
Copy link
Member

pierrejeambrun commented Jul 15, 2025

@jason810496 needs manual cherry picking I guess, or this fix won't be in the next patch release.

@jason810496
Copy link
Member Author

Thanks for the reminder! I will raise backport PR when I back to home

jason810496 added a commit to jason810496/airflow that referenced this pull request Jul 15, 2025
* Respect apps flags for api_server_command

* Refactor test_api_apps_env

(cherry picked from commit c0c41ff)
@kaxil
Copy link
Member

kaxil commented Jul 15, 2025

Cool, thanks. Please do when you get time

Thanks for the reminder! I will raise backport PR when I back to home

jason810496 added a commit to jason810496/airflow that referenced this pull request Jul 26, 2025
* Respect apps flags for api_server_command

* Refactor test_api_apps_env

(cherry picked from commit c0c41ff)
jason810496 added a commit to jason810496/airflow that referenced this pull request Jul 26, 2025
* Respect apps flags for api_server_command

* Refactor test_api_apps_env

(cherry picked from commit c0c41ff)
potiuk pushed a commit that referenced this pull request Jul 26, 2025
)

* Respect apps flags for api_server_command

* Refactor test_api_apps_env

(cherry picked from commit c0c41ff)
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:CLI backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants