Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No current database" error when moving to home page from schema page #3720

Closed
pavish opened this issue Aug 1, 2024 · 0 comments · Fixed by #3723
Closed

"No current database" error when moving to home page from schema page #3720

pavish opened this issue Aug 1, 2024 · 0 comments · Fixed by #3723
Assignees
Labels
regression restricted: maintainers Only maintainers can resolve this issue work: frontend Related to frontend code in the mathesar_ui directory

Comments

@pavish
Copy link
Member

pavish commented Aug 1, 2024

Description

  • Navigate to the schema page (/http://localhost:8000/db/<db_id>/<schema_id>/ where tables are listed.
  • Click on the Mathesar icon in the breadcrumbs (It redirects to /).
  • Notice an error being thrown on the console:
    Uncaught (in promise) Error: No current database
     at databases.ts:110:17
     at sync (chunk-46BDKJIK.js?v=a71937be:71:22)
     at Array.<anonymous> (chunk-46BDKJIK.js?v=a71937be:82:9)
     at Object.set (chunk-46BDKJIK.js?v=a71937be:30:35)
     at DatabasesStore.clearCurrentDatabaseId (databases.ts:96:28)
     at handleUnmount (DatabaseRoute.svelte:22:20)
     at run (chunk-WAIAKUYY.js?v=a71937be:19:10)
     at Array.forEach (<anonymous>)
     at run_all (chunk-WAIAKUYY.js?v=a71937be:25:7)
     at destroy_component (chunk-WAIAKUYY.js?v=a71937be:1672:5)
    
  • The app crashes after that i.e. no other action is possible until a full reload.
  • We discussed throwing this error in Implement tables.list and tables.delete RPC APIs on the schema page #3651, however, we missed testing the scenario of the unmounting of DatabaseRoute during review.

Some possible causes

  • This error is related to this line and here.
  • The DatabaseRoute is unmounted while visiting /, which sets databasesStore.currentDatabaseId to undefined.
  • This in turn results in databasesStore.currentDatabase being undefined.
  • There are two possible causes for this:
  • The most possible cause:
    • The tables store uses the currentDatabase store. The tables store is initialized when visiting the schema page.
    • This keeps the currentDatabase store in use.
    • Since the Svelte stores within tables store are long living and live on the highest app context, they never get destroyed. This is by design. (Eg., currentTablesData derived store).
    • This keeps currentDatabase subscribed even when moving to the base / route.
  • Another less-possible cause:
    • Svelte derived store seems to perform a sync action during unsubscribing if the store had been set a value before (i.e. inited), which forcibly syncs the currentDatabase store throwing the error since the value is undefined.
        const unsubscribers = stores_array.map((store, i) => subscribe(store, (value) => {
          values[i] = value;
          pending &= ~(1 << i);
          if (inited) {
            sync();
          }
        }, () => {
          pending |= 1 << i;
        }));
      
      Refer this line in the svelte repository.

Expected behavior

  • There should be no error.
@pavish pavish added type: bug restricted: maintainers Only maintainers can resolve this issue labels Aug 1, 2024
@pavish pavish added this to the Beta milestone Aug 1, 2024
@pavish pavish added work: frontend Related to frontend code in the mathesar_ui directory regression labels Aug 1, 2024
@kgodey kgodey modified the milestones: Beta, Pre-beta test build #1 Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression restricted: maintainers Only maintainers can resolve this issue work: frontend Related to frontend code in the mathesar_ui directory
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants