Skip to content

Conversation

@moshemorad
Copy link
Contributor

@moshemorad moshemorad commented Nov 2, 2025

@moshemorad moshemorad requested a review from arikalon1 November 2, 2025 18:10
@coderabbitai
Copy link

coderabbitai bot commented Nov 2, 2025

Walkthrough

A module-level monkey-patch is applied to Supabase's request builder pre_select to normalize returned QueryArgs by setting falsy json values to None; the patch is installed at import time and logs the patching action.

Changes

Cohort / File(s) Summary
Supabase request builder normalization
src/robusta/core/sinks/robusta/dal/supabase_dal.py
Added import of QueryArgs and supabase_request_builder from postgrest, installed a wrapper around pre_select that normalizes QueryArgs by setting json to None when falsy, and added module-level logging indicating the patch was applied.

Sequence Diagram(s)

sequenceDiagram
    participant Module as supabase_dal.py (module import)
    participant Builder as supabase_request_builder
    participant Caller as Any code calling pre_select

    rect #f8f9fa
      Module->>Builder: import builder\nimport QueryArgs
      Module->>Builder: wrap pre_select with normalizer
      Note right of Module: logs "patched pre_select"
    end

    Caller->>Builder: pre_select(...)
    alt patched flow
        Builder->>Builder: original pre_select(...)
        Builder-->>Builder: returns QueryArgs (maybe json falsy)
        Builder->>Builder: normalizer: if not json -> set json = None
        Builder-->>Caller: normalized QueryArgs
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify correct import paths and types for QueryArgs and supabase_request_builder.
  • Confirm wrapper preserves original behavior for non-falsy json and handles all falsy cases safely.
  • Review logging placement and ensure no unintended side effects at module import time.

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description Check ❓ Inconclusive The pull request description consists only of a hyperlink to another PR (https://github.com/robusta-dev/relay/pull/307) with no explanatory text. While this may be related to the changeset based on the branch name (ROB-2502-upgrade-runner-supabase-version), the description is extremely minimal and lacks any descriptive content that conveys meaningful information about what the changeset actually does or why the patch was needed.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Patch pre_select supabase" directly and specifically describes the main change in the changeset. The raw summary confirms the primary alteration is patching supabase_request_builder.pre_select with a wrapper function to normalize QueryArgs behavior. The title is concise, clear, and specific enough that a developer scanning the repository history would immediately understand the purpose of this change without ambiguity.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ROB-2502-upgrade-runner-supabase-version

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

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

Copy link

@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

🧹 Nitpick comments (1)
src/robusta/core/sinks/robusta/dal/supabase_dal.py (1)

61-69: Make the monkey patch idempotent

If this module gets re-imported (for example in tests that call importlib.reload), we will wrap the already-patched pre_select again, stacking extra call layers. It still works, but each reload adds another wrapper, making debugging and profiling noisy. Please gate the patch so it only runs once.

-logging.info("Patching supabase_request_builder.pre_select")
-original_pre_select = supabase_request_builder.pre_select
-def pre_select_patched(*args, **kwargs):
-    args: QueryArgs = original_pre_select(*args, **kwargs)
-    if not args.json:
-        args = QueryArgs(args.method, args.params, args.headers, None)
-
-    return args
-supabase_request_builder.pre_select = pre_select_patched
+if not getattr(supabase_request_builder.pre_select, "_robusta_patch", False):
+    logging.info("Patching supabase_request_builder.pre_select")
+    original_pre_select = supabase_request_builder.pre_select
+
+    def pre_select_patched(*args, **kwargs):
+        args: QueryArgs = original_pre_select(*args, **kwargs)
+        if not args.json:
+            args = QueryArgs(args.method, args.params, args.headers, None)
+        return args
+
+    pre_select_patched._robusta_patch = True
+    supabase_request_builder.pre_select = pre_select_patched

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used**: CodeRabbit UI

**Review profile**: CHILL

**Plan**: Pro

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 060705b8917306ae9aca725499e7731698e280c0 and a15d83c1ebac61fc9bf48158bf91f8e1c35247d2.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `src/robusta/core/sinks/robusta/dal/supabase_dal.py` (3 hunks)

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)</summary>

* GitHub Check: run_tests
* GitHub Check: run_tests
* GitHub Check: Deploy docs

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link

@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: 1

🧹 Nitpick comments (1)
src/robusta/core/sinks/robusta/dal/supabase_dal.py (1)

61-61: Consider log level for production environments.

The INFO-level log will appear in all production logs. If this patch becomes stable and well-understood, consider lowering to DEBUG to reduce log verbosity.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a15d83c and d40bc7d.

📒 Files selected for processing (1)
  • src/robusta/core/sinks/robusta/dal/supabase_dal.py (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: run_tests
  • GitHub Check: run_tests
🔇 Additional comments (3)
src/robusta/core/sinks/robusta/dal/supabase_dal.py (3)

13-13: LGTM!

The QueryArgs import is necessary for the monkey-patch implementation and is imported from a public module.


63-68: Patch logic appears correct, pending constructor verification.

The normalization logic correctly handles falsy json values by explicitly setting them to None. This preserves method, params, and headers while normalizing the json field.

However, ensure that:

  1. The QueryArgs constructor signature matches this call (4 positional arguments)
  2. There are no other fields in QueryArgs that need to be preserved

40-40: Accessing private postgrest module risks breakage with library updates.

The import from postgrest._sync and monkey-patching of pre_select at lines 40 and 62–69 rely on internal implementation details not exposed in postgrest-py's public API. The _sync module and pre_select are internal, non-public helpers—documented public alternatives are the SyncPostgrestClient interfaces (e.g., .select(), .execute()).

With postgrest 0.16.8 still actively developed, these internal details could change in minor or patch releases, breaking this workaround. Consider:

  • Reporting this limitation to postgrest-py maintainers to expose pre_select publicly
  • Filing a GitHub issue documenting the JSON serialization issue this patch addresses
  • Tracking this as technical debt until a stable public API alternative is available

@arikalon1 arikalon1 merged commit 86ac4a5 into master Nov 3, 2025
6 checks passed
@arikalon1 arikalon1 deleted the ROB-2502-upgrade-runner-supabase-version branch November 3, 2025 08:13
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