Skip to content

fix(match): create the Supabase client on first use - #317

Merged
Saahi30 merged 1 commit into
mainfrom
fix/match-lazy-supabase
Oct 13, 2026
Merged

Saahi30 merged 1 commit into
mainfrom
fix/match-lazy-supabase

Conversation

@Saahi30

@Saahi30 Saahi30 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • main.py imports the match router, and that imports Backend/app/services/db_service.py, which built a Supabase client at import time.
  • A missing SUPABASE_URL or SUPABASE_KEY still killed startup even after the AI routes were fixed.
  • The client is now created on the first match call. Missing config returns 503 from that call.

This is separate from #316, which does the same thing for the post routes. Both are needed before the API can import with those variables unset.

Test plan

  • Import app.services.db_service with SUPABASE_URL and SUPABASE_KEY unset and confirm it does not raise.
  • Call GET /match/brands-for-creator/{id} with those vars unset and confirm a 503.
  • Call the same route with valid Supabase credentials and confirm it still returns matches.

Summary by CodeRabbit

  • Bug Fixes
    • Database-backed matching now responds with a clear service-unavailable status when required database settings are missing, instead of failing unexpectedly.
    • Matching results and behavior when no results are found remain unchanged.

Importing the match service no longer crashes the API when SUPABASE_URL or SUPABASE_KEY is missing.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 21:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: AOSSIE-Org/InPactAI/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 6dfd77ef-a072-4d7a-9af2-72418d4f3678
📥 Commits

Reviewing files that changed from the base of the PR and between 98ef3fb and 40fd13b.

📒 Files selected for processing: 1
  • Backend/app/services/db_service.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

Supabase client creation now occurs on first use through a cached helper. Both matching functions obtain database access through this helper. Missing required configuration causes an HTTP 503 response.

Changes

Supabase access

Layer / File(s) Summary
Lazy client and matching queries
Backend/app/services/db_service.py
get_supabase() creates and caches the client on first use, and raises HTTP 503 if either required environment variable is missing. Both matching functions use the helper. Their query conditions and empty-result behavior remain unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: Python Lang

Merge Risk: ⚪ Minimal · up to 40fd1

With Supabase configuration missing, the matching routes return 503 rather than failing during import. The inspected route handling supports that behavior, and no actionable merge-blocking risk is established.

Pre-merge checks: Passed 4
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: lazy creation of the Supabase client on first use.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit watched the client wake,
On first request, a link to make.
It saved the handle for the day,
And sent both matching calls its way.
If keys were missing, 503 came,
Then hopped back home, content all the same.

Comment @coderabbitai help to get the list of available commands.

@Saahi30
Saahi30 merged commit 20b83e4 into main Oct 13, 2026
3 checks passed
@gitcordapp

gitcordapp Bot commented Oct 14, 2026

Copy link
Copy Markdown

Link your account with Gitcord

Thanks for opening this PR, @Saahi30!

To receive Discord notifications and contributor tracking for this organization:

  1. Join Discord: https://discord.gg/hjUhu33uAn
  2. In Discord, run /link Saahi30
  3. Paste the verification code into your GitHub bio (or a public gist)
  4. Click Verify in Discord (or run /verify-link Saahi30)

Once linked, Gitcord can notify you about reviews, merges, and more.

— Posted by Gitcord

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.

2 participants