Skip to content

UI: Set the API client base URL before the first startup request - #72374

Merged
bbovenzi merged 1 commit into
apache:mainfrom
edsu:fix-ui-base-path-during-init
Sep 4, 2026
Merged

bbovenzi merged 1 commit into
apache:mainfrom
edsu:fix-ui-base-path-during-init

Conversation

@edsu

@edsu edsu commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

When Airflow is served under a path prefix, the UI sent its first API request to the origin root instead of the prefix.

OpenAPI.BASE was assigned as a module side effect in queryClient.ts, which imports src/i18n/config. That module requests the version at module scope to build a translation cache buster, and ES module evaluation runs a dependency to completion before the importing module's body, so the request always went out while BASE was still "". The generated client builds its URL as config.BASE + path, so the request was sent to the origin root.

The consequences depend on what else is mounted at /api/. In our case the request reaches a different service API, that responded with a 401, which the UI reads as an expired session, which redirects to login, which succeeds and reloads, producing an infinite login loop. The request also defeats the feature it exists for: the lookup fails, resolveI18nVersion falls back to Date.now(), and translations are fetched with a timestamp instead of the version.

Move the base href resolution and the client configuration into src/basePath, a module with no application dependencies, and have i18n/config take its base path from there. The ordering guarantee then comes from a real data dependency rather than from the import graph happening to line up.

utils/links.ts still reads <base href> separately, but it does so at call time rather than module scope, so it is unaffected; consolidating it is left out to keep this change to the bug.

Adds a regression test that fails on main with
expected [ '/api/v2/version' ] to deeply equal [].

Closes: #72344


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [Claude Code (Opus 5)] following the guidelines

@boring-cyborg boring-cyborg Bot added the area:UI Related to UI/UX. For Frontend Developers. label Sep 1, 2026
@boring-cyborg

boring-cyborg Bot commented Sep 1, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@ashb

ashb commented Sep 2, 2026

Copy link
Copy Markdown
Member

@bbovenzi PTAL

@edsu
edsu force-pushed the fix-ui-base-path-during-init branch from 9bd1cb5 to 3cefbe5 Compare September 3, 2026 13:38
When Airflow is served under a path prefix, the UI sent its first API request
to the origin root instead of the prefix.

`OpenAPI.BASE` was assigned as a module side effect in `queryClient.ts`, which
imports `src/i18n/config`. That module requests the version at module scope to
build a translation cache buster, and ES module evaluation runs a dependency to
completion before the importing module's body, so the request always went out
while `BASE` was still `""`. The generated client builds its URL as
`config.BASE + path`, so the request was sent to the origin root.

The consequences depend on what else is mounted at `/api/`. In our case
the request reaches a different service, which responded with a 401
which the UI reads as an expired session, which redirects to login,
which succeeds and reloads, producing an infinite login loop. The
request also defeats the feature it exists for: the lookup fails,
`resolveI18nVersion` falls back to `Date.now()`, and translations are
fetched with a timestamp instead of the version.

Move the base href resolution and the client configuration into `src/basePath`,
a module with no application dependencies, and have `i18n/config` take its base
path from there. The ordering guarantee then comes from a real data dependency
rather than from the import graph happening to line up.

`utils/links.ts` still reads `<base href>` separately, but it does so at call
time rather than module scope, so it is unaffected; consolidating it is left
out to keep this change to the bug.

Adds a regression test that fails on main with
`expected [ '/api/v2/version' ] to deeply equal []`.

Closes: apache#72344
@edsu
edsu force-pushed the fix-ui-base-path-during-init branch from 3cefbe5 to 5b19646 Compare September 3, 2026 13:39
@bbovenzi

bbovenzi commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Looks like we need to fix the E2E tests

@bbovenzi

bbovenzi commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Nevermind tests are unrelated

@bbovenzi
bbovenzi merged commit 1c23f87 into apache:main Sep 4, 2026
84 of 87 checks passed
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
❌ v3-3-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 1c23f87 v3-3-test

This should apply the commit to the v3-3-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

If you don't have cherry-picker installed, see the installation guide.

@pierrejeambrun pierrejeambrun left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. A couple of nits to make the code easier to read.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove this file please.

Comment on lines +25 to +39
export const basePath = new URL(baseHref, globalThis.location.origin).pathname.replace(/\/$/u, "");

// The generated client is configured here, in a module with no app dependencies, rather
// than next to the query client. Anything that issues a request while the app is still
// initializing has to observe the configured base -- i18n requests the version at module
// scope to build a cache buster -- and importing that request's module first would
// otherwise send it to the origin root instead of the prefix. Importing anything derived
// from the base href now orders this assignment ahead of the request.
OpenAPI.BASE = baseHref.endsWith("/") ? baseHref.slice(0, -1) : baseHref;

// Encode path params as full URI components so values containing "/" (e.g. a variable key
// like "/foo") become "%2Ffoo" rather than a literal "//", which proxies may collapse. The
// generated client otherwise defaults to encodeURI, which leaves "/" untouched.
// The backend automatically decodes path params.
OpenAPI.ENCODE_PATH = encodeURIComponent;

@pierrejeambrun pierrejeambrun Sep 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: I'm not a fan of this. Having the setup done every time, in an implicit way through a side effect.

I would rather have the basePath handle the path only. Have the api init declared somewhere else in another file specific to apiclient or something, to separate concerns.

And have that API init function called at the root of the application once, explicitly.


// Also configures the generated client, which must happen before the version
// request below. See src/basePath.
import { basePath } from "src/basePath";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Basically if this was "configureClient" instead of "basePath" this comment wouldn't be needed

edsu added a commit to edsu/airflow that referenced this pull request Sep 7, 2026
…che#72374)

When Airflow is served under a path prefix, the UI sent its first API request
to the origin root instead of the prefix.

`OpenAPI.BASE` was assigned as a module side effect in `queryClient.ts`, which
imports `src/i18n/config`. That module requests the version at module scope to
build a translation cache buster, and ES module evaluation runs a dependency to
completion before the importing module's body, so the request always went out
while `BASE` was still `""`. The generated client builds its URL as
`config.BASE + path`, so the request was sent to the origin root.

The consequences depend on what else is mounted at `/api/`. In our case
the request reaches a different service, which responded with a 401
which the UI reads as an expired session, which redirects to login,
which succeeds and reloads, producing an infinite login loop. The
request also defeats the feature it exists for: the lookup fails,
`resolveI18nVersion` falls back to `Date.now()`, and translations are
fetched with a timestamp instead of the version.

Move the base href resolution and the client configuration into `src/basePath`,
a module with no application dependencies, and have `i18n/config` take its base
path from there. The ordering guarantee then comes from a real data dependency
rather than from the import graph happening to line up.

`utils/links.ts` still reads `<base href>` separately, but it does so at call
time rather than module scope, so it is unaffected; consolidating it is left
out to keep this change to the bug.

Adds a regression test that fails on main with
`expected [ '/api/v2/version' ] to deeply equal []`.

Closes: apache#72344
pierrejeambrun pushed a commit that referenced this pull request Sep 9, 2026
) (#72733)

When Airflow is served under a path prefix, the UI sent its first API request
to the origin root instead of the prefix.

`OpenAPI.BASE` was assigned as a module side effect in `queryClient.ts`, which
imports `src/i18n/config`. That module requests the version at module scope to
build a translation cache buster, and ES module evaluation runs a dependency to
completion before the importing module's body, so the request always went out
while `BASE` was still `""`. The generated client builds its URL as
`config.BASE + path`, so the request was sent to the origin root.

The consequences depend on what else is mounted at `/api/`. In our case
the request reaches a different service, which responded with a 401
which the UI reads as an expired session, which redirects to login,
which succeeds and reloads, producing an infinite login loop. The
request also defeats the feature it exists for: the lookup fails,
`resolveI18nVersion` falls back to `Date.now()`, and translations are
fetched with a timestamp instead of the version.

Move the base href resolution and the client configuration into `src/basePath`,
a module with no application dependencies, and have `i18n/config` take its base
path from there. The ordering guarantee then comes from a real data dependency
rather than from the import graph happening to line up.

`utils/links.ts` still reads `<base href>` separately, but it does so at call
time rather than module scope, so it is unaffected; consolidating it is left
out to keep this change to the bug.

Adds a regression test that fails on main with
`expected [ '/api/v2/version' ] to deeply equal []`.

Closes: #72344
(cherry picked from commit 1c23f87)

Co-authored-by: Ed Summers <[email protected]>
edsu added a commit to blue-core-lod/bluecore-workflows that referenced this pull request Oct 20, 2026
Bump the base image and the apache-airflow pin from 3.2.0 to 3.3.2, and raise
the keycloak provider floor to 0.10.0.

3.3.1 had no working configuration for this deployment. 3.3.2 includes the
backport of apache/airflow#72374 (#72733), which fixes the UI login loop when
Airflow is served under a path prefix such as /workflows. Provider 0.10.0
includes apache/airflow#72381, which keeps the Keycloak tokens in the Airflow
JWT claims so "Authorization: Bearer" API clients authenticate again. Older
providers either break Bearer auth (0.9.x) or ship no refresh middleware
(<0.9.0), so the floor rules both out.

The relock moves fastapi (0.148.0 -> 0.136.3) and cadwyn (7.4.0 -> 7.0.0)
down, to the versions airflow-core 3.3.2 allows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI Related to UI/UX. For Frontend Developers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI: API requests bypass <base href> during startup, breaking deployments served under a path prefix

4 participants