Fix PostgreSQL query placeholders and console type imports - #69
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 911f727a78
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| def _postgres_query(query: str) -> str: | ||
| """Convert the qmark placeholders used by callers to psycopg's format.""" | ||
| return query.replace("?", "%s") |
There was a problem hiding this comment.
Preserve non-placeholder question marks
When a caller submits valid PostgreSQL syntax containing a question mark that is not a qmark binding—such as the JSONB existence expression payload ? 'key'—this unconditional replacement turns the operator into %s, causing psycopg to interpret it as a parameter placeholder and reject or misexecute the query. Translate only actual bind markers, or use dialect-specific query strings, so PostgreSQL operators and question marks in literals/comments remain intact.
Useful? React with 👍 / 👎.
Motivation
psycopgreceives correctly formatted parameter placeholders when shared SQLite-style?queries are reused.NameErrorin Streamlit helpers by adding the missing typing names used in nested helper annotations.Description
_postgres_queryhelper incura_frame/db.pythat converts?placeholders to psycopg-compatible%sand apply it toexecute,fetchone, andfetchallPostgreSQL branches.from typing import Any, Dictinapps/console_streamlit/app.pyto satisfy nested helper annotations used by the Streamlit UI.test_postgres_operations_convert_qmark_placeholderstotests/test_console_db_auth.pyexercisingexecute,fetchone, andfetchallagainst a fake Postgres cursor to verify placeholder conversion and result shaping.Testing
pytest -qand confirmed test suite success with191 passed(warnings shown but unrelated to these changes).pytest -q tests/test_console_db_auth.py tests/test_web.pywhich passed (coverage of the added regression test included).ruff checkandpython -m compileallto validate style/type imports and byte-compile the package, both completed without errors.Codex Task