MagicStack / MagicStack/asyncpg
Unable to use f-string in SqlAlchemy ORM
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 8.1k
- フォーク
- 468
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
- asyncpg version: 0.23.0
- PostgreSQL version: 12
- Python version: 3.9.4
- Platform: OSX
- Do you use pgbouncer?: No
- Did you install asyncpg with pip?: pipenv
- If you built asyncpg locally, which version of Cython did you use?: N/A
- Can the issue be reproduced under both asyncio and
uvloop?: N/A
I'm trying to build a SQL statement with LIKE expression and a pattern but I'm getting an error.
Here is what I had in the code originally:
statement = select(Customer).options(sqlalchemy.orm.joinedload(Customer.transactions)).where(Customer.l_name.ilike(name))
and this worked great.
But if I want to use this statement with a % pattern like this:
statement = f'select(Customer).options(sqlalchemy.orm.joinedload(Customer.transactions)).where(Customer.l_name.ilike("%{name}%"))'
I get this error:
sqlalchemy.exc.ProgrammingError: (sqlalchemy.dialects.postgresql.asyncpg.ProgrammingError) <class 'asyncpg.exceptions.PostgresSyntaxError'>: syntax error at or near "("
[SQL: select(Customer).options(sqlalchemy.orm.joinedload(Customer.transactions)).where(Customer.l_name.ilike("%%turing%%"))]
It does substitute the variable with a parameter but for some reason it adds an extra pair of percent signs and crashes.
How can I solve this problem?
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
asyncpg のファイル、テスト、またはエントリーポイントは指定されていません。まず、提示された SQLAlchemy 式と生成された SQL を確認し、その後、動作が asyncpg で再現するのか、それとも ORM ステートメントを文字列として構築したことに起因するのかを検証してください。結果を、記載されている PostgreSQL と asyncpg のバージョンに照らして確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- postgresql, python
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 22/100