Skip to content

Commit 3ed39ca

Browse files
alukachgadomski
authored andcommitted
fix: avoid f-string in queries
Backport of stac-utils/stac-fastapi#554
1 parent f9570d2 commit 3ed39ca

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

stac_fastapi/pgstac/db.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import attr
88
import orjson
99
from asyncpg import exceptions, pool
10-
from buildpg import asyncpg, render
10+
from buildpg import V, asyncpg, render
1111
from fastapi import FastAPI
1212
from stac_fastapi.types.errors import (
1313
ConflictError,
@@ -65,18 +65,20 @@ async def dbfunc(pool: pool, func: str, arg: Union[str, Dict]):
6565
if isinstance(arg, str):
6666
async with pool.acquire() as conn:
6767
q, p = render(
68-
f"""
69-
SELECT * FROM {func}(:item::text);
68+
"""
69+
SELECT * FROM :func(:item::text);
7070
""",
71+
func=V(func),
7172
item=arg,
7273
)
7374
return await conn.fetchval(q, *p)
7475
else:
7576
async with pool.acquire() as conn:
7677
q, p = render(
77-
f"""
78-
SELECT * FROM {func}(:item::text::jsonb);
78+
"""
79+
SELECT * FROM :func(:item::text::jsonb);
7980
""",
81+
func=V(func),
8082
item=json.dumps(arg),
8183
)
8284
return await conn.fetchval(q, *p)

0 commit comments

Comments
 (0)