Skip to content

Conversation

amotl
Copy link
Member

@amotl amotl commented Sep 5, 2025

About

A workaround for a yet unknown bug submitted by @tomach last week. Is it applicable or can we find a different one?

Copy link

coderabbitai bot commented Sep 5, 2025

Walkthrough

Adds native CrateDB HTTP API support for crate://...native=true URIs, derives a cleaned HTTPS native_url and dburi_clean, conditionally connects via crate_client (native) or SQLAlchemy (non-native), executes SQL via POST to .../_sql in native mode, and standardizes result shaping and return semantics.

Changes

Cohort / File(s) Summary
CrateDB native HTTP support and execution path
cratedb_toolkit/util/database.py
Detects crate://...native=true to enable native mode; derives native_url and dburi_clean; connects via crate_client.connect (ssl_verify=False) when native and logs [Native]; otherwise uses SQLAlchemy and logs [SQLAlchemy]. run_sql_real branches: native issues POST to native_url/_sql with stmt/args, parses {cols, rows} into dicts when records=True; non-native path preserved. Unified single-item return rule; inline comments replace the former run_sql_real docstring.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant DB as util.database
  participant CrateClient as crate_client
  participant SQLA as SQLAlchemy
  participant HTTP as CrateDB HTTP _sql

  Caller->>DB: run_sql_real(dburi, statements, params, records)
  alt crate:// and native=true
    Note over DB: [Native] path — crate_client + HTTP
    DB->>CrateClient: connect(dburi_clean, ssl_verify=False)
    loop for each statement
      DB->>HTTP: POST native_url/_sql { stmt, args }
      HTTP-->>DB: { cols, rows, ... } or error
      alt records == True
        Note right of DB: map rows -> dicts using cols
      else
        Note right of DB: return raw rows
      end
    end
  else non-native / other schemes
    Note over DB: [SQLAlchemy] path
    DB->>SQLA: create_engine(dburi) / execute(stmt, params)
    loop for each statement
      SQLA-->>DB: results
    end
  end
  alt single statement
    DB-->>Caller: single result
  else multiple statements
    DB-->>Caller: list of results
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I sniff the URL, a crate in sight,
Native whispers or SQL's light.
I hop to POST with curly rows,
Or bind with engines when it slows.
One result I carry, many I store—thump, explore! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ad2f1a6 and b90e194.

📒 Files selected for processing (1)
  • cratedb_toolkit/util/database.py (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cratedb_toolkit/util/database.py (2)
cratedb_toolkit/model.py (4)
  • dburi (103-107)
  • DatabaseAddress (55-197)
  • from_string (63-72)
  • from_string (223-224)
cratedb_toolkit/adapter/rockset/server/api/query.py (1)
  • execute (36-68)
🪛 Ruff (0.12.2)
cratedb_toolkit/util/database.py

162-162: Probable use of requests call without timeout

(S113)


164-164: Probable use of requests call with verify=False disabling SSL certificate checks

(S501)

🪛 GitHub Actions: Tests: Common
cratedb_toolkit/util/database.py

[error] 162-162: Ruff check: S113 Probable use of requests call without timeout.


[error] 164-164: Ruff check: S501 Probable use of requests call with verify=False disabling SSL certificate checks.

⏰ 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). (6)
  • GitHub Check: build-and-publish
  • GitHub Check: build-and-test
  • GitHub Check: CFR for OS windows-latest
  • GitHub Check: CFR for OS ubuntu-latest
  • GitHub Check: CFR for OS macos-13
  • GitHub Check: CFR for OS macos-latest
🔇 Additional comments (2)
cratedb_toolkit/util/database.py (2)

176-186: SQLAlchemy execution path looks good.

with self.ctx is applied; mappings().fetchall() for records=True is correct.


189-189: Return-shape normalization is fine.

Single-statement returns scalar result; multi-statement returns list.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ta/settings-compare-workaround

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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: 6

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 10a20a8 and ad2f1a6.

📒 Files selected for processing (1)
  • cratedb_toolkit/util/database.py (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cratedb_toolkit/util/database.py (2)
cratedb_toolkit/model.py (4)
  • dburi (103-107)
  • DatabaseAddress (55-197)
  • from_string (63-72)
  • from_string (223-224)
cratedb_toolkit/adapter/rockset/server/api/query.py (1)
  • execute (36-68)
🪛 Ruff (0.12.2)
cratedb_toolkit/util/database.py

162-162: Probable use of requests call without timeout

(S113)


164-164: Probable use of requests call with verify=False disabling SSL certificate checks

(S501)

⏰ 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). (8)
  • GitHub Check: build-and-publish
  • GitHub Check: build-and-test
  • GitHub Check: Generic: Python 3.13 on OS ubuntu-latest
  • GitHub Check: Generic: Python 3.9 on OS ubuntu-latest
  • GitHub Check: CFR for OS windows-latest
  • GitHub Check: CFR for OS macos-13
  • GitHub Check: CFR for OS macos-latest
  • GitHub Check: CFR for OS ubuntu-latest
🔇 Additional comments (2)
cratedb_toolkit/util/database.py (2)

176-186: SQLAlchemy path looks fine.

Context manager is applied; result shaping mirrors prior behavior.


189-189: Single-item unwrapping is safe: downstream callers either index into the returned data or ignore the return value, and existing tests (e.g. tests/util/database.py) already expect [(1,)] rather than a nested list. No further changes needed.

@amotl amotl force-pushed the ta/settings-compare-workaround branch from ad2f1a6 to b90e194 Compare September 5, 2025 08:59
@amotl
Copy link
Member Author

amotl commented Sep 19, 2025

Hi @tomach. Do you need this change? Please let us know so we may be able to help accordingly. 🙏

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