Skip to content

Commit 2978b4f

Browse files
authored
Merge pull request #8 from Veritaris/bump-psqlpy-and-taskiq
Bump PSQLPy and taskiq
2 parents 0020d8c + efca50c commit 2978b4f

File tree

7 files changed

+769
-609
lines changed

7 files changed

+769
-609
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
pytest:
2828
strategy:
2929
matrix:
30-
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
30+
py_version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
3131
runs-on: "ubuntu-latest"
3232
steps:
3333
- uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ repos:
1212
- repo: https://github.com/asottile/add-trailing-comma
1313
rev: v2.1.0
1414
hooks:
15-
- id: add-trailing-comma
15+
- id: add-trailing-comma
1616

1717
- repo: local
1818
hooks:
19-
- id: black
20-
name: Format with Black
21-
entry: poetry run black
22-
language: system
23-
types: [python]
24-
2519
- id: ruff
2620
name: Run ruff lints
27-
entry: poetry run ruff
21+
entry: poetry run ruff check
2822
language: system
2923
pass_filenames: false
30-
types: [python]
24+
types: [ python ]
3125
args:
3226
- "--fix"
3327
- "taskiq_psqlpy"
3428
- "tests"
3529

30+
- id: black
31+
name: Format with Black
32+
entry: poetry run black
33+
language: system
34+
types: [ python ]
35+
3636
- id: mypy
3737
name: Validate types with MyPy
3838
entry: poetry run mypy

poetry.lock

Lines changed: 672 additions & 517 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "taskiq-psqlpy"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
description = "PSQLPy and PostgreSQL integration for taskiq"
55
authors = ["taskiq-team <[email protected]>"]
66
readme = "README.md"
@@ -9,11 +9,11 @@ classifiers = [
99
"Programming Language :: Python",
1010
"Programming Language :: Python :: 3",
1111
"Programming Language :: Python :: 3 :: Only",
12-
"Programming Language :: Python :: 3.8",
1312
"Programming Language :: Python :: 3.9",
1413
"Programming Language :: Python :: 3.10",
1514
"Programming Language :: Python :: 3.11",
1615
"Programming Language :: Python :: 3.12",
16+
"Programming Language :: Python :: 3.13",
1717
]
1818
homepage = "https://github.com/taskiq-python/taskiq-psqlpy"
1919
repository = "https://github.com/taskiq-python/taskiq-psqlpy"
@@ -28,14 +28,14 @@ keywords = [
2828
]
2929

3030
[tool.poetry.dependencies]
31-
python = "^3.8.1"
32-
psqlpy = "^0.8.7"
33-
taskiq = "^0.11.10"
31+
python = "^3.9.0"
32+
psqlpy = "^0.11.1"
33+
taskiq = "^0.11.17"
3434

3535
[tool.poetry.group.dev.dependencies]
3636
black = "^23.1.0"
3737
pre-commit = "^2.20.0"
38-
mypy = "^1.1.1"
38+
mypy = "^1.16"
3939
flake8 = "^6"
4040
autoflake = "^1.4"
4141
yesqa = "^1.4.0"
@@ -44,7 +44,7 @@ pytest-xdist = "^3.2.1"
4444
anyio = "^3.6.2"
4545
pytest-cov = "^4.0.0"
4646
wemake-python-styleguide = "^0.18.0"
47-
ruff = "^0.3.4"
47+
ruff = "^0.12"
4848

4949

5050
[tool.mypy]
@@ -63,68 +63,68 @@ requires = ["poetry-core>=1.0.0"]
6363
build-backend = "poetry.core.masonry.api"
6464

6565
[tool.ruff]
66+
line-length = 88
67+
68+
[tool.ruff.lint]
6669
# List of enabled rulsets.
6770
# See https://docs.astral.sh/ruff/rules/ for more information.
6871
select = [
69-
"E", # Error
70-
"F", # Pyflakes
71-
"W", # Pycodestyle
72+
"E", # Error
73+
"F", # Pyflakes
74+
"W", # Pycodestyle
7275
"C90", # McCabe complexity
73-
"I", # Isort
74-
"N", # pep8-naming
75-
"D", # Pydocstyle
76+
"I", # Isort
77+
"N", # pep8-naming
78+
"D", # Pydocstyle
7679
"ANN", # Pytype annotations
77-
"S", # Bandit
78-
"B", # Bugbear
80+
"S", # Bandit
81+
"B", # Bugbear
7982
"COM", # Commas
80-
"C4", # Comprehensions
83+
"C4", # Comprehensions
8184
"ISC", # Implicit string concat
8285
"PIE", # Unnecessary code
8386
"T20", # Catch prints
8487
"PYI", # validate pyi files
85-
"Q", # Checks for quotes
88+
"Q", # Checks for quotes
8689
"RSE", # Checks raise statements
8790
"RET", # Checks return statements
8891
"SLF", # Self checks
8992
"SIM", # Simplificator
9093
"PTH", # Pathlib checks
9194
"ERA", # Checks for commented out code
92-
"PL", # PyLint checks
95+
"PL", # PyLint checks
9396
"RUF", # Specific to Ruff checks
9497
]
9598
ignore = [
96-
"D105", # Missing docstring in magic method
97-
"D107", # Missing docstring in __init__
98-
"D212", # Multi-line docstring summary should start at the first line
99-
"D401", # First line should be in imperative mood
100-
"D104", # Missing docstring in public package
101-
"D100", # Missing docstring in public module
102-
"ANN102", # Missing type annotation for self in method
103-
"ANN101", # Missing type annotation for argument
104-
"ANN401", # typing.Any are disallowed in `**kwargs
99+
"D105", # Missing docstring in magic method
100+
"D107", # Missing docstring in __init__
101+
"D212", # Multi-line docstring summary should start at the first line
102+
"D401", # First line should be in imperative mood
103+
"D104", # Missing docstring in public package
104+
"D100", # Missing docstring in public module
105+
"ANN401", # typing.Any are disallowed in `**kwargs
105106
"PLR0913", # Too many arguments for function call
106-
"D106", # Missing docstring in public nested class
107+
"D106", # Missing docstring in public nested class
107108
]
108109
exclude = [".venv/"]
109110
mccabe = { max-complexity = 10 }
110-
line-length = 88
111111

112-
[tool.ruff.per-file-ignores]
112+
[tool.ruff.lint.per-file-ignores]
113113
"tests/*" = [
114-
"S101", # Use of assert detected
115-
"S301", # Use of pickle detected
116-
"D103", # Missing docstring in public function
114+
"S101", # Use of assert detected
115+
"S301", # Use of pickle detected
116+
"D103", # Missing docstring in public function
117117
"SLF001", # Private member accessed
118-
"S311", # Standard pseudo-random generators are not suitable for security/cryptographic purposes
119-
"D101", # Missing docstring in public class
118+
"S311", # Standard pseudo-random generators are not suitable for security/cryptographic purposes
119+
"D101", # Missing docstring in public class
120120
]
121121

122-
[tool.ruff.pydocstyle]
122+
[tool.ruff.lint.pydocstyle]
123123
convention = "pep257"
124124
ignore-decorators = ["typing.overload"]
125125

126-
[tool.ruff.pylint]
126+
[tool.ruff.lint.pylint]
127127
allow-magic-value-types = ["int", "str", "float"]
128128

129-
[tool.ruff.flake8-bugbear]
129+
[tool.ruff.lint.flake8-bugbear]
130130
extend-immutable-calls = ["taskiq_dependencies.Depends", "taskiq.TaskiqDepends"]

taskiq_psqlpy/result_backend.py

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
)
99

1010
from psqlpy import ConnectionPool
11-
from psqlpy.exceptions import RustPSQLDriverPyBaseError
11+
from psqlpy._internal.exceptions import InterfaceError
12+
from psqlpy.exceptions import DatabaseError
1213
from taskiq import AsyncResultBackend, TaskiqResult
1314
from taskiq.abc.serializer import TaskiqSerializer
1415
from taskiq.compat import model_dump, model_validate
@@ -67,18 +68,20 @@ async def startup(self) -> None:
6768
dsn=self.dsn,
6869
**self.connect_kwargs,
6970
)
70-
await self._database_pool.execute(
71-
querystring=CREATE_TABLE_QUERY.format(
72-
self.table_name,
73-
self.field_for_task_id,
74-
),
75-
)
76-
await self._database_pool.execute(
77-
querystring=CREATE_INDEX_QUERY.format(
78-
self.table_name,
79-
self.table_name,
80-
),
81-
)
71+
async with self._database_pool.acquire() as connection:
72+
await connection.execute(
73+
querystring=CREATE_TABLE_QUERY.format(
74+
self.table_name,
75+
self.field_for_task_id,
76+
),
77+
)
78+
async with self._database_pool.acquire() as connection:
79+
await connection.execute(
80+
querystring=CREATE_INDEX_QUERY.format(
81+
self.table_name,
82+
self.table_name,
83+
),
84+
)
8285

8386
async def shutdown(self) -> None:
8487
"""Close the connection pool."""
@@ -94,15 +97,16 @@ async def set_result(
9497
:param task_id: ID of the task.
9598
:param result: result of the task.
9699
"""
97-
await self._database_pool.execute(
98-
querystring=INSERT_RESULT_QUERY.format(
99-
self.table_name,
100-
),
101-
parameters=[
102-
task_id,
103-
self.serializer.dumpb(model_dump(result)),
104-
],
105-
)
100+
async with self._database_pool.acquire() as connection:
101+
await connection.execute(
102+
querystring=INSERT_RESULT_QUERY.format(
103+
self.table_name,
104+
),
105+
parameters=[
106+
task_id,
107+
self.serializer.dumpb(model_dump(result)),
108+
],
109+
)
106110

107111
async def is_result_ready(self, task_id: str) -> bool:
108112
"""Returns whether the result is ready.
@@ -135,26 +139,27 @@ async def get_result(
135139
:raises ResultIsMissingError: if there is no result when trying to get it.
136140
:return: TaskiqResult.
137141
"""
138-
connection: Final = await self._database_pool.connection()
139142
try:
140-
result_in_bytes: Final[bytes] = await connection.fetch_val(
141-
querystring=SELECT_RESULT_QUERY.format(
142-
self.table_name,
143-
),
144-
parameters=[task_id],
145-
)
146-
except RustPSQLDriverPyBaseError as exc:
143+
async with self._database_pool.acquire() as connection:
144+
result_in_bytes: Final[bytes] = await connection.fetch_val(
145+
querystring=SELECT_RESULT_QUERY.format(
146+
self.table_name,
147+
),
148+
parameters=[task_id],
149+
)
150+
except (DatabaseError, InterfaceError) as exc:
147151
raise ResultIsMissingError(
148152
f"Cannot find record with task_id = {task_id} in PostgreSQL",
149153
) from exc
150154

151155
if not self.keep_results:
152-
await self._database_pool.execute(
153-
querystring=DELETE_RESULT_QUERY.format(
154-
self.table_name,
155-
),
156-
parameters=[task_id],
157-
)
156+
async with self._database_pool.acquire() as conn:
157+
await conn.execute(
158+
querystring=DELETE_RESULT_QUERY.format(
159+
self.table_name,
160+
),
161+
parameters=[task_id],
162+
)
158163

159164
taskiq_result: Final = model_validate(
160165
TaskiqResult[_ReturnType],

tests/conftest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ async def psqlpy_result_backend(
6060
)
6161
await backend.startup()
6262
yield backend
63-
await backend._database_pool.execute(
64-
querystring=f"DROP TABLE {postgres_table}",
65-
)
63+
async with backend._database_pool.acquire() as connection:
64+
await connection.execute(
65+
querystring=f"DROP TABLE {postgres_table}",
66+
)
6667
await backend.shutdown()

tests/test_result_backend.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ async def test_success_backend_default_result_delete_res(
8989
with pytest.raises(expected_exception=ResultIsMissingError):
9090
await backend.get_result(task_id=task_id)
9191

92-
await backend._database_pool.execute(
93-
querystring=f"DROP TABLE {postgres_table}",
94-
)
92+
async with backend._database_pool.acquire() as connection:
93+
await connection.execute(
94+
querystring=f"DROP TABLE {postgres_table}",
95+
)
9596

9697
await backend.shutdown()
9798

@@ -106,7 +107,6 @@ async def test_success_backend_default_result(
106107
107108
:param default_taskiq_result: TaskiqResult with default result.
108109
:param task_id: ID for task.
109-
:param nats_urls: urls to NATS.
110110
"""
111111
await psqlpy_result_backend.set_result(
112112
task_id=task_id,
@@ -127,7 +127,6 @@ async def test_success_backend_custom_result(
127127
128128
:param custom_taskiq_result: TaskiqResult with custom result.
129129
:param task_id: ID for task.
130-
:param redis_url: url to redis.
131130
"""
132131
await psqlpy_result_backend.set_result(
133132
task_id=task_id,

0 commit comments

Comments
 (0)