Skip to content

Conversation

@morgan-wowk
Copy link

@morgan-wowk morgan-wowk commented Dec 17, 2025

Description

Added BACKEND_QUERY_KEY to React Query hooks and updated query keys to ensure proper cache invalidation when the backend URL changes. This fixes issues where data wasn't being properly fetched when using a custom backend URL instead of the default one.

The changes include:

  • Removing backendUrl from query keys to ensure cache is shared regardless of URL
  • Adding BACKEND_QUERY_KEY prefix to backend-dependent queries
  • Adding !!configured to query enabled conditions to prevent fetching before backend is configured
  • Implementing cache invalidation when backend URL changes
  • Adding tests to verify backend configuration behavior

Related issue

#1575

To Reproduce the bug on master

  1. Open your database / backend connection preferences in the top right of the page
  2. Set a custom backend to http://localhost:8000
  3. Save.
  4. Reload the homepage.
  5. Select a run.
  6. Reload the page when the URL is /runs/{id}
    • At this point, you should see an error.

Before fix

image.png

After fix

image.png

Type of Change

  • Bug fix
  • Improvement
  • Cleanup/Refactor

Checklist

  • I have tested this does not break current pipelines / runs functionality
  • I have tested the changes on staging

Test Instructions

  1. Configure multiple backend URLs in settings
  2. Regression test submitting runs, and loading run pages using the refresh button of the browser (as well as coming from the homepage)
  3. Verify that data is properly fetched with and without custom backend enabled

Copy link
Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@morgan-wowk morgan-wowk marked this pull request as ready for review December 17, 2025 21:29
@morgan-wowk morgan-wowk requested a review from a team as a code owner December 17, 2025 21:29
@morgan-wowk morgan-wowk force-pushed the 12-17-fix_querying_data_unreliable_with_custom_backend branch 5 times, most recently from da96890 to e87c01c Compare December 17, 2025 22:01
Copy link
Collaborator

@maxy-shpfy maxy-shpfy left a comment

Choose a reason for hiding this comment

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

Adding "backendUrl" as part of query key seems to be not feasiable at scale.

Have you tried to invalidate ALL queries when we change backend settings?

See https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation

@morgan-wowk morgan-wowk force-pushed the 12-17-fix_querying_data_unreliable_with_custom_backend branch 3 times, most recently from 26c3495 to b530eca Compare December 18, 2025 00:05
@morgan-wowk morgan-wowk force-pushed the 12-17-fix_querying_data_unreliable_with_custom_backend branch from b530eca to 033ffd3 Compare December 18, 2025 00:26
Copy link
Author

Adding "backendUrl" as part of query key seems to be not feasiable at scale.

Have you tried to invalidate ALL queries when we change backend settings?

See https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation

This is a great point. Thank you.

There are 4 local queries to (static YAML, IndexedDB, in-memory parsing).

I have added backend flag to all queries that hit the backend, and adjusted the solution to invalidate all backend queries when backend settings change.

@morgan-wowk morgan-wowk force-pushed the 12-17-fix_querying_data_unreliable_with_custom_backend branch from 033ffd3 to 2c3b459 Compare December 18, 2025 00:33
Copy link
Author

morgan-wowk commented Dec 18, 2025

Based on my analysis of the code, the old keys are in-memory and will be:

  • Garbage-collected after 5 minutes
  • Cleared on page reload

@morgan-wowk morgan-wowk requested a review from a team December 18, 2025 01:13
@morgan-wowk morgan-wowk marked this pull request as draft December 19, 2025 22:28
@morgan-wowk morgan-wowk removed request for a team and maxy-shpfy December 19, 2025 22:28
@morgan-wowk morgan-wowk force-pushed the 12-17-fix_querying_data_unreliable_with_custom_backend branch 2 times, most recently from 20b8dd5 to ee33d9f Compare December 19, 2025 22:58
**Changes:**

* Clear backend query cache when backend settings change
* Wait until we have determined the backend url fully before executing backend queries
@morgan-wowk morgan-wowk force-pushed the 12-17-fix_querying_data_unreliable_with_custom_backend branch from ee33d9f to 903f8b0 Compare December 19, 2025 23:02
@morgan-wowk morgan-wowk marked this pull request as ready for review December 19, 2025 23:06
@morgan-wowk morgan-wowk requested review from a team and maxy-shpfy December 19, 2025 23:06
Copy link
Author

Update

Verified that this fix supports:

Local environments ✅

  • Using .env file with VITE_BACKEND_API_URL
  • Using the custom backend feature pointed to http://localhost:8000

Remote environments ✅

  • With no .env or VITE_BACKEND_API_URL , and serving the backend API on the same domain at /api (using nginx).
  • I have tested this locally by running my own nginx server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants