Skip to content

Commit 01bc0d5

Browse files
alukachgadomski
andauthored
Avoid fstring in queries (#554)
* Avoid fstring in queries * Reorder import * chore: update changelog --------- Co-authored-by: Pete Gadomski <[email protected]>
1 parent 1ca37cd commit 01bc0d5

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
* Default branch to **main** ([#544](https://github.com/stac-utils/stac-fastapi/pull/544))
88

9+
### Fixed
10+
11+
* Use `V()` instead of f-strings for pgstac queries ([#554](https://github.com/stac-utils/stac-fastapi/pull/554))
12+
913
## [2.4.4] - 2023-03-09
1014

1115
### Added

stac_fastapi/pgstac/stac_fastapi/pgstac/db.py

Lines changed: 9 additions & 7 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

1313
from stac_fastapi.types.errors import (
@@ -66,18 +66,20 @@ async def dbfunc(pool: pool, func: str, arg: Union[str, Dict]):
6666
if isinstance(arg, str):
6767
async with pool.acquire() as conn:
6868
q, p = render(
69-
f"""
70-
SELECT * FROM {func}(:item::text);
71-
""",
69+
"""
70+
SELECT * FROM :func(:item::text);
71+
""",
72+
func=V(func),
7273
item=arg,
7374
)
7475
return await conn.fetchval(q, *p)
7576
else:
7677
async with pool.acquire() as conn:
7778
q, p = render(
78-
f"""
79-
SELECT * FROM {func}(:item::text::jsonb);
80-
""",
79+
"""
80+
SELECT * FROM :func(:item::text::jsonb);
81+
""",
82+
func=V(func),
8183
item=json.dumps(arg),
8284
)
8385
return await conn.fetchval(q, *p)

0 commit comments

Comments
 (0)