Skip to content

Supabase: Select Row sometimes returns errors #17057

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

Merged
merged 5 commits into from
Jun 12, 2025
Merged

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented Jun 10, 2025

Resolves #17043

I was able to reproduce the error, but I discovered that it was because my Project had been paused due to inactivity. Once reactivated, the error went away.

However, I found several online comments about similar sporadic errors, and that the "fetch failed" error can stem from various issues, including network problems. So I added a retryWithExponentialBackoff method to help reduce errors.

Summary by CodeRabbit

  • New Features

    • Added automatic retry with exponential backoff for row selection operations, improving reliability in case of temporary errors.
  • Bug Fixes

    • Corrected summary messages for row selection to accurately display the number of rows retrieved and improved grammatical correctness.
  • Chores

    • Updated version numbers for Supabase actions, sources, and package to reflect recent changes.

Copy link

vercel bot commented Jun 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Jun 11, 2025 4:38pm
pipedream-docs ⬜️ Ignored (Inspect) Jun 11, 2025 4:38pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jun 11, 2025 4:38pm

Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

Walkthrough

This update primarily increments version numbers across multiple Supabase action and source components. Additionally, a new retry mechanism with exponential backoff was introduced in the Supabase app module, and the selectRow method was modified to use this retry logic for improved reliability.

Changes

Files Change Summary
components/supabase/actions/*/*.mjs (batch-insert-rows, delete-row, insert-row, remote-procedure-call, update-row, upsert-row) Version numbers incremented (e.g., 0.0.1 → 0.0.2, 0.1.2 → 0.1.3) without other changes.
components/supabase/actions/select-row/select-row.mjs Version updated 0.1.2 → 0.1.3; summary message corrected to use response.data?.length and improved grammar.
components/supabase/sources/new-row-added/new-row-added.mjs Version updated 0.0.4 → 0.0.5.
components/supabase/sources/new-webhook-event/new-webhook-event.mjs Version updated 0.0.5 → 0.0.6.
components/supabase/package.json Package version updated from 0.3.0 to 0.3.1.
components/supabase/supabase.app.mjs Added retryWithExponentialBackoff method; modified selectRow to use retry logic with exponential backoff.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant SupabaseApp as Supabase App
    participant SupabaseAPI as Supabase API

    Caller->>SupabaseApp: selectRow(args)
    SupabaseApp->>SupabaseApp: retryWithExponentialBackoff(func)
    SupabaseApp->>SupabaseAPI: execute query
    SupabaseAPI-->>SupabaseApp: response or error
    alt success
        SupabaseApp-->>Caller: return response
    else failure and attempts left
        SupabaseApp->>SupabaseApp: wait exponential delay
        SupabaseApp->>SupabaseAPI: retry query
    else failure and no attempts left
        SupabaseApp-->>Caller: throw error
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement retry logic with exponential backoff to reduce intermittent errors in selectRow (#17043) selectRow now uses retryWithExponentialBackoff to handle fetch failures and retry accordingly.
Fix error handling in selectRow to prevent returning errors due to transient fetch failures (#17043) The retry logic catches errors and retries instead of immediately failing, reducing error return frequency.

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected. All changes align with version bumps or the retry logic implementation to address the linked issue.

Poem

🐇 Hop, hop, hooray! A retry dance today,
Fetch may stumble, but now it won't stray.
With backoff steps, errors fade away,
Rows come safely, bright as day!
Version bumps cheer, let's all play! 🎉🐰

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

components/supabase/supabase.app.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:201:49)

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@michelle0927 michelle0927 marked this pull request as ready for review June 10, 2025 20:34
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
components/supabase/actions/batch-insert-rows/batch-insert-rows.mjs (1)

9-9: Version updated – verify changelog entry

Only the version was incremented. Ensure the corresponding changelog (if maintained) records this bump so downstream users understand that no behavioural change was shipped.

components/supabase/actions/select-row/select-row.mjs (2)

84-85: Refine summary message for accurate pluralisation & robustness

row(s) is serviceable, but a small tweak yields cleaner output and avoids ambiguity while still guarding against undefined:

-$.export("$summary", `Successfully retrieved ${response.data?.length || 0} row(s) from table ${table}`);
+const count = response.data?.length ?? 0;
+$.export(
+  "$summary",
+  `Successfully retrieved ${count} ${count === 1 ? "row" : "rows"} from table ${table}`,
+);

75-83: Consider propagating the new retry logic to other data-access methods

selectRow now benefits from the internal exponential-backoff wrapper added in supabase.app.mjs.
It may be worth providing analogous resilience for insertRow, upsertRow, etc., to offer a uniform developer experience and minimise transient network issues across all actions.

components/supabase/supabase.app.mjs (1)

69-70: Initial delay is 1 s, not the advertised baseDelayS (2 s)

Because Math.pow(baseDelayS, attempt) starts with attempt = 0, the first delay becomes 1 s.
If you keep the existing maths, use (attempt + 1) to honour the stated base.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22c0e45 and 5088088.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • components/supabase/actions/batch-insert-rows/batch-insert-rows.mjs (1 hunks)
  • components/supabase/actions/delete-row/delete-row.mjs (1 hunks)
  • components/supabase/actions/insert-row/insert-row.mjs (1 hunks)
  • components/supabase/actions/remote-procedure-call/remote-procedure-call.mjs (1 hunks)
  • components/supabase/actions/select-row/select-row.mjs (2 hunks)
  • components/supabase/actions/update-row/update-row.mjs (1 hunks)
  • components/supabase/actions/upsert-row/upsert-row.mjs (1 hunks)
  • components/supabase/package.json (1 hunks)
  • components/supabase/sources/new-row-added/new-row-added.mjs (1 hunks)
  • components/supabase/sources/new-webhook-event/new-webhook-event.mjs (1 hunks)
  • components/supabase/supabase.app.mjs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Lint Code Base
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (9)
components/supabase/package.json (1)

3-3: Approve version bump to 0.3.1
Consistent metadata update aligning with other Supabase component modules.

components/supabase/actions/remote-procedure-call/remote-procedure-call.mjs (1)

7-7: Approve version bump to 0.1.3
No changes to logic; version increment aligns with coordinated updates.

components/supabase/actions/update-row/update-row.mjs (1)

7-7: Approve version bump to 0.1.3
No functional changes; version increment is in sync with other actions.

components/supabase/actions/delete-row/delete-row.mjs (1)

7-7: Approve version bump to 0.1.3
Version update only—logic unchanged and consistent across modules.

components/supabase/sources/new-row-added/new-row-added.mjs (1)

12-12: Approve version bump to 0.0.5
Matches the coordinated version increment across Supabase sources and actions.

components/supabase/actions/insert-row/insert-row.mjs (1)

7-7: Patch-level version bump looks good

No functional changes are introduced in this file and the version bump keeps semantic-versioning discipline.
Nothing else to flag here.

components/supabase/sources/new-webhook-event/new-webhook-event.mjs (1)

8-8: Source version bump acknowledged

No additional feedback – implementation remains unchanged.

components/supabase/actions/upsert-row/upsert-row.mjs (1)

7-7: Minor version increment OK

LGTM.

components/supabase/actions/select-row/select-row.mjs (1)

8-8: Version increment consistent with other actions

Nothing further.

GTFalcao
GTFalcao previously approved these changes Jun 11, 2025
Copy link
Collaborator

@GTFalcao GTFalcao left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
components/supabase/supabase.app.mjs (1)

55-78: 🛠️ Refactor suggestion

Exponential-backoff math & recursion could be streamlined

  1. delayMs = Math.pow(baseDelayS, attempt) * 1000 yields 1 s for the first retry regardless of baseDelayS (because attempt starts at 0).
    Most callers expect the first retry to wait baseDelayS seconds (e.g. 2 s), then 4 s, 8 s…

  2. The self-recursion is harmless at 3 attempts, yet a simple loop is clearer and avoids stack growth if maxAttempts is increased later.

Proposed tweak:

-    retryWithExponentialBackoff(func, maxAttempts = 3, baseDelayS = 2) {
-      let attempt = 0;
+    async retryWithExponentialBackoff(func, maxAttempts = 3, baseDelayS = 2) {
+      for (let attempt = 0; attempt < maxAttempts; attempt++) {
+        try {
+          const resp = await func();
+          this.verifyForErrors(resp);
+          return resp;
+        } catch (error) {
+          if (attempt === maxAttempts - 1) throw error;
+
+          const delayMs = Math.pow(baseDelayS, attempt + 1) * 1000; // 2s, 4s, 8s …
+          await new Promise((r) => setTimeout(r, delayMs));
+        }
+      }
+    },

Keeps the public contract (“up to maxAttempts tries”) while matching the expected delay curve.

🧹 Nitpick comments (1)
components/supabase/supabase.app.mjs (1)

90-97: Drop the unnecessary ctx alias

Arrow functions already capture this; introducing const ctx = this is redundant and flagged by Biome (noUselessThisAlias). Inline this for brevity:

-      const ctx = this;
-      const resp = await this.retryWithExponentialBackoff(async () => {
-        let query = ctx.baseFilter(client, table, orderBy, ascending, max);
-        if (filter) {
-          query = ctx[filter](query, column, value);
-        }
+      const resp = await this.retryWithExponentialBackoff(async () => {
+        let query = this.baseFilter(client, table, orderBy, ascending, max);
+        if (filter) {
+          query = this[filter](query, column, value);
+        }
         return await query;
       });
🧰 Tools
🪛 Biome (1.9.4)

[error] 90-90: This aliasing of this is unnecessary.

Arrow functions inherits this from their enclosing scope.
Safe fix: Use this instead of an alias.

(lint/complexity/noUselessThisAlias)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1d2657 and eb41d07.

📒 Files selected for processing (1)
  • components/supabase/supabase.app.mjs (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
components/supabase/supabase.app.mjs

[error] 90-90: This aliasing of this is unnecessary.

Arrow functions inherits this from their enclosing scope.
Safe fix: Use this instead of an alias.

(lint/complexity/noUselessThisAlias)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Lint Code Base
🔇 Additional comments (1)
components/supabase/supabase.app.mjs (1)

92-97: 👍 Query rebuilt per attempt – stale-fetch issue resolved

Moving the query construction inside the retry callback ensures each attempt creates a fresh Postgrest builder. This eliminates the stale / closed fetches problem noted earlier.

@michelle0927
Copy link
Collaborator Author

/approve

@michelle0927 michelle0927 merged commit f1eb5a3 into master Jun 12, 2025
11 checks passed
@michelle0927 michelle0927 deleted the issue-17043 branch June 12, 2025 20:44
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.

[BUG] Supabase: Select Row sometimes returns errors
2 participants