Skip to content

sqlite3: raise ProgrammingError when named param receives sequence - #8363

Merged
youknowone merged 1 commit into
RustPython:mainfrom
ever0de:fix/sqlite-named-param-sequence-check
Jul 26, 2026
Merged

sqlite3: raise ProgrammingError when named param receives sequence#8363
youknowone merged 1 commit into
RustPython:mainfrom
ever0de:fix/sqlite-named-param-sequence-check

Conversation

@ever0de

@ever0de ever0de commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

CPython raises ProgrammingError with "Binding N is a named parameter" when a query uses named placeholders (, , ) but
the caller passes a sequence instead of a mapping.

RustPython's bind_parameters_sequence() did not check whether each binding slot is a named parameter, so no error was raised.

Fix: call sqlite3_bind_parameter_name() for each slot in bind_parameters_sequence(). If the first byte of the returned name is not '?' (i.e. it is a named placeholder), raise ProgrammingError before attempting to bind.

Assisted-by: GitHub Copilot:claude-sonnet-4-6

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved SQL parameter sequence binding validation by detecting use of named parameters and raising a clearer error that sequences require nameless ? placeholders.
  • Chores
    • Updated spell-check configuration to always recognize the term “qmark”.

Copilot AI review requested due to automatic review settings July 25, 2026 09:06
@ever0de
ever0de marked this pull request as draft July 25, 2026 09:06
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: bddb3a42-5383-4f49-9dae-7c0d72c47782

📥 Commits

Reviewing files that changed from the base of the PR and between 15ee651 and 09715f1.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_sqlite3/test_dbapi.py is excluded by !Lib/**
📒 Files selected for processing (2)
  • .cspell.json
  • crates/stdlib/src/_sqlite3.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • .cspell.json
  • crates/stdlib/src/_sqlite3.rs

📝 Walkthrough

Walkthrough

SQLite sequence parameter binding now checks parameter names and raises ProgrammingError when named parameters are supplied through a sequence. The spelling configuration also recognizes qmark.

Changes

SQLite parameter binding

Layer / File(s) Summary
Validate named parameters during sequence binding
crates/stdlib/src/_sqlite3.rs, .cspell.json
bind_parameters_sequence inspects SQLite parameter names and rejects named parameters when values are provided as a sequence; qmark is added to the spelling dictionary.

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

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 matches the main change: sqlite3 now raises ProgrammingError when a sequence is used with named parameters.
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 unit tests (beta)
  • Create PR with unit tests

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.

🔧 Biome (2.5.3)
.cspell.json

File contains syntax errors that prevent linting: Line 1: Expected an array, an object, or a literal but instead found '// See: https://github.com/streetsidesoftware/cspell/tree/; Line 6: Expected an array, an object, or a literal but instead found '// "@cspell/dict-cpp/cspell-ext.json",'.; Line 2: End of file expected; Line 6: End of file expected; Line 7: End of file expected; Line 7: End of file expected; Line 8: End of file expected; Line 8: End of file expected; Line 9: End of file expected; Line 9: End of file expected; Line 10: End of file expected; Line 10: End of file expected; Line 12: End of file expected; Line 12: End of file expected; Line 12: End of file expected; Line 12: End of file expected; Line 14: End of file expected; Line 14: End of file expected; Line 14: End of file expected; Line 14: End of file expected; Line 16: End of file expected; Line 16: End of file expected; Line 17: Expected an array, an object, or a literal but instead found '// Sometimes keeping same

... [truncated 1271 characters] ...

; Line 102: End of file expected; Line 103: End of file expected; Line 103: End of file expected; Line 104: End of file expected; Line 104: End of file expected; Line 105: End of file expected; Line 105: End of file expected; Line 106: End of file expected; Line 106: End of file expected; Line 107: End of file expected; Line 107: End of file expected; Line 109: End of file expected; Line 110: End of file expected; Line 112: End of file expected; Line 112: End of file expected; Line 112: End of file expected; Line 113: End of file expected; Line 114: End of file expected; Line 114: End of file expected; Line 114: End of file expected; Line 115: End of file expected; Line 117: End of file expected; Line 117: End of file expected; Line 117: End of file expected; Line 123: End of file expected


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.

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/sqlite3
[x] test: cpython/Lib/test/test_sqlite3 (TODO: 79)

dependencies:

  • sqlite3

dependent tests: (2 tests)

  • sqlite3: test_dbm_sqlite3 test_sqlite3

[x] lib: cpython/Lib/ast.py
[x] lib: cpython/Lib/_ast_unparse.py
[x] test: cpython/Lib/test/test_unparse.py
[x] test: cpython/Lib/test/test_type_comments.py

dependencies:

  • ast

dependent tests: (149 tests)

  • ast: test_ast test_builtin test_compile test_compiler_codegen test_dis test_fstring test_future_stmt test_peepholer test_peg_generator test_site test_ssl test_type_comments test_ucn test_unparse
    • annotationlib: test_annotationlib test_functools test_grammar test_inspect test_reprlib test_type_annotations test_type_params test_typing
      • dataclasses: test__colorize test_copy test_ctypes test_enum test_genericalias test_patma test_pprint test_pydoc test_regrtest test_zoneinfo
      • inspect: test_abc test_argparse test_asyncgen test_buffer test_clinic test_code test_collections test_coroutines test_decimal test_generators test_monitoring test_ntpath test_operator test_posixpath test_signal test_sqlite3 test_traceback test_turtle test_types test_unittest test_yield_from test_zipimport test_zipimport_support
    • dbm.dumb: test_dbm_dumb
    • inspect:
      • bdb: test_bdb test_pdb
      • cmd: test_cmd
      • importlib.metadata: test_importlib
      • pkgutil: test_pkgutil test_pyrepl test_runpy
      • rlcompleter: test_pyrepl test_rlcompleter
      • trace: test_trace
      • xmlrpc.server: test_docxmlrpc test_xmlrpc
    • pyclbr: test_pyclbr
    • traceback: test_asyncio test_code_module test_contextlib test_contextlib_async test_dictcomps test_exceptions test_http_cookiejar test_importlib test_iter test_listcomps test_pyexpat test_setcomps test_socket test_subprocess test_sys test_threadedtempfile test_threading test_unittest test_with
      • concurrent.futures.process: test_compileall test_concurrent_futures
      • http.cookiejar: test_urllib2
      • logging: test_asyncio test_hashlib test_logging test_support test_urllib2net
      • multiprocessing: test_asyncio test_concurrent_futures test_fcntl test_memoryview test_multiprocessing_main_handling test_re
      • py_compile: test_cmd_line_script test_importlib test_modulefinder test_py_compile
      • socketserver: test_imaplib test_socketserver test_wsgiref
      • threading: test_android test_asyncio test_bytes test_bz2 test_concurrent_futures test_context test_ctypes test_email test_external_inspection test_fork1 test_frame test_ftplib test_gc test_httplib test_httpservers test_importlib test_io test_ioctl test_itertools test_largefile test_linecache test_opcache test_pathlib test_poll test_poplib test_pyrepl test_queue test_robotparser test_sched test_smtplib test_super test_syslog test_termios test_threading_local test_time test_urllib2_localnet test_weakref test_winreg test_zstd
      • timeit: test_timeit

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

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.

Pull request overview

This PR aligns RustPython’s sqlite3 parameter binding behavior with CPython by raising ProgrammingError when a statement contains named placeholders (e.g., :a, :b) but the caller supplies a positional sequence instead of a mapping.

Changes:

  • Add a named-parameter check to bind_parameters_sequence() using sqlite3_bind_parameter_name() and raise ProgrammingError when a named placeholder is detected.
  • Unmark test_execute_named_param_and_sequence as expectedFailure now that RustPython enforces the same validation as CPython.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/stdlib/src/_sqlite3.rs Adds named-placeholder detection during sequence binding and raises ProgrammingError early for mixed named/positional usage with a sequence.
Lib/test/test_sqlite3/test_dbapi.py Removes the RustPython expectedFailure marker for the named-param-with-sequence validation test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3206 to +3212
let name = unsafe { sqlite3_bind_parameter_name(self.st, i) };
if !name.is_null() && unsafe { *name } != b'?' as i8 {
return Err(new_programming_error(
vm,
format!("Binding {i} is a named parameter, but you supplied a sequence instead of a dict."),
));
}

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/stdlib/src/_sqlite3.rs (1)

3206-3211: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Make the c_char comparison target-independent.

sqlite3_bind_parameter_name() returns *const c_char, while b'?' as i8 assumes c_char is signed. Rust defines C char as platform-dependent (i8 or u8), so this can fail to compile on supported targets using unsigned char. (doc.rust-lang.org)

Suggested fix
-                if !name.is_null() && unsafe { *name } != b'?' as i8 {
+                if !name.is_null() && unsafe { *name as u8 } != b'?' {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/stdlib/src/_sqlite3.rs` around lines 3206 - 3211, Update the
comparison in the parameter-name validation around sqlite3_bind_parameter_name
to use the platform’s c_char type rather than casting b'?' to i8. Preserve the
existing null check and error behavior while making the comparison compile for
both signed- and unsigned-char targets.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/stdlib/src/_sqlite3.rs`:
- Around line 3206-3211: Update the comparison in the parameter-name validation
around sqlite3_bind_parameter_name to use the platform’s c_char type rather than
casting b'?' to i8. Preserve the existing null check and error behavior while
making the comparison compile for both signed- and unsigned-char targets.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2315ca3c-c85e-4d0e-9356-6df47741f3a2

📥 Commits

Reviewing files that changed from the base of the PR and between 28454cc and 68b534d.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_sqlite3/test_dbapi.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/stdlib/src/_sqlite3.rs

Copilot AI review requested due to automatic review settings July 25, 2026 09:12
@ever0de
ever0de force-pushed the fix/sqlite-named-param-sequence-check branch from 68b534d to 45c9cc1 Compare July 25, 2026 09:12
@ever0de
ever0de force-pushed the fix/sqlite-named-param-sequence-check branch from 45c9cc1 to 872ecd7 Compare July 25, 2026 09:14

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

crates/stdlib/src/_sqlite3.rs:3207

  • The comparison unsafe { *name } != b'?' as i8 assumes c_char is signed. On targets where libc::c_char is u8, this can fail to compile (or lead to incorrect casts). Cast the literal to libc::c_char (or compare as u8) to keep this portable.
                if !name.is_null() && unsafe { *name } != b'?' as libc::c_char {

Copilot AI review requested due to automatic review settings July 25, 2026 09:15
@ever0de
ever0de force-pushed the fix/sqlite-named-param-sequence-check branch from 872ecd7 to 1508cb1 Compare July 25, 2026 09:21
@ever0de
ever0de marked this pull request as ready for review July 25, 2026 09:22

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 25, 2026 09: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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +3211 to +3214
format!(
"Binding {i} ('{name_str}') is a named parameter, but you \
supplied a sequence which requires nameless (qmark) placeholders."
),
Copilot AI review requested due to automatic review settings July 25, 2026 09:29
@ever0de
ever0de force-pushed the fix/sqlite-named-param-sequence-check branch from 1508cb1 to de95ea8 Compare July 25, 2026 09:29

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 25, 2026 09:33
@ever0de
ever0de force-pushed the fix/sqlite-named-param-sequence-check branch from de95ea8 to 15ee651 Compare July 25, 2026 09:33

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

CPython raises ProgrammingError with "Binding N is a named parameter"
when a query uses named placeholders (, , ) but
the caller passes a sequence instead of a mapping.

RustPython's bind_parameters_sequence() did not check whether each
binding slot is a named parameter, so no error was raised.

Fix: call sqlite3_bind_parameter_name() for each slot in
bind_parameters_sequence(). If the first byte of the returned name is
not '?' (i.e. it is a named placeholder), raise ProgrammingError before
attempting to bind.

Assisted-by: GitHub Copilot:claude-sonnet-4-6
Copilot AI review requested due to automatic review settings July 25, 2026 10:58
@ever0de
ever0de force-pushed the fix/sqlite-named-param-sequence-check branch from 15ee651 to 09715f1 Compare July 25, 2026 10:58

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@youknowone
youknowone merged commit cc6c638 into RustPython:main Jul 26, 2026
27 checks passed
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