Repository navigation
UI: Set the API client base URL before the first startup request - #72374
Conversation
|
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
|
|
@bbovenzi PTAL |
9bd1cb5 to
3cefbe5
Compare
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
3cefbe5 to
5b19646
Compare
|
Looks like we need to fix the E2E tests |
|
Nevermind tests are unrelated |
Backport failed to create: v3-3-test. View the failure log Run detailsNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
You can attempt to backport this manually by running: cherry_picker 1c23f87 v3-3-testThis should apply the commit to the v3-3-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
| 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; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Basically if this was "configureClient" instead of "basePath" this comment wouldn't be needed
…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
) (#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]>
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]>
When Airflow is served under a path prefix, the UI sent its first API request to the origin root instead of the prefix.
OpenAPI.BASEwas assigned as a module side effect inqueryClient.ts, which importssrc/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 whileBASEwas still"". The generated client builds its URL asconfig.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,resolveI18nVersionfalls back toDate.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 havei18n/configtake 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.tsstill 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?
Generated-by: [Claude Code (Opus 5)] following the guidelines