Skip to content

Commit bedad57

Browse files
Add support for Django 5.2 and bump version to 0.0.13 (#14)
* Add support for Django 5.2 and bump version to 0.0.13 Co-Authored-By: Nishant Singh <[email protected]> * changes * fix * fix * use postgres 14 * fix * fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Nishant Singh <[email protected]>
1 parent 6014b90 commit bedad57

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

.github/workflows/test.yml

+12-5
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,25 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17+
psycopg-package: ["psycopg2", "psycopg"]
1718
python-version: ["3.9", "3.10", "3.11"]
18-
django-version: ["4.0", "4.1", "4.2", "5.0", "5.1"]
19+
django-version: ["4.0", "4.1", "4.2", "5.0", "5.1", "5.2"]
1920
exclude:
20-
# Django 5.0+ requires Python 3.10+
2121
- python-version: "3.9"
2222
django-version: "5.0"
2323
- python-version: "3.9"
2424
django-version: "5.1"
25-
max-parallel: 5
25+
- python-version: "3.9"
26+
django-version: "5.2"
27+
- django-version: "4.0"
28+
psycopg-package: "psycopg"
29+
- django-version: "4.1"
30+
psycopg-package: "psycopg"
31+
max-parallel: 20
2632

2733
services:
2834
postgres:
29-
image: postgres:13
35+
image: postgres:14
3036
env:
3137
POSTGRES_PASSWORD: postgres
3238
options: >-
@@ -50,7 +56,8 @@ jobs:
5056
# Install main dependencies, dev dependencies, and the specific Django version for the matrix
5157
# Using -e .[dev] installs the current package in editable mode with dev extras
5258
uv pip install --system -e .[dev]
53-
uv pip install --system Django==${{ matrix.django-version }}
59+
pip install Django==${{ matrix.django-version }}
60+
pip install ${{ matrix.psycopg-package }}
5461
- name: Run tests
5562
run: |
5663
./check-lint.sh

django_querysets_single_query_fetch/service.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
get_related_populators,
2525
)
2626
from django.utils.dateparse import parse_datetime
27-
from psycopg2.extensions import QuotedString
2827

2928
logger = logging.getLogger(__name__)
3029

@@ -189,6 +188,19 @@ def _get_compiler_from_queryset(self, queryset: QuerysetWrapperType) -> Any:
189188

190189
return compiler
191190

191+
def _get_sanitized_sql_param(self, param: str) -> str:
192+
try:
193+
from psycopg import sql
194+
195+
return sql.quote(param)
196+
except ImportError:
197+
try:
198+
from psycopg2.extensions import QuotedString
199+
200+
return QuotedString(param).getquoted().decode("utf-8")
201+
except ImportError:
202+
raise ImportError("psycopg or psycopg2 not installed")
203+
192204
def _get_django_sql_for_queryset(self, queryset: QuerysetWrapperType) -> str:
193205
"""
194206
gets the sql that django would normally execute for the queryset, return empty string
@@ -212,7 +224,7 @@ def _get_django_sql_for_queryset(self, queryset: QuerysetWrapperType) -> str:
212224
for param in params:
213225
if isinstance(param, str):
214226
# this is to handle special char handling
215-
param = QuotedString(param).getquoted().decode("utf-8")
227+
param = self._get_sanitized_sql_param(param)
216228
elif isinstance(param, UUID) or isinstance(param, datetime.datetime):
217229
param = f"'{param}'"
218230
elif isinstance(param, int) or isinstance(param, float):
@@ -419,7 +431,7 @@ def execute(self) -> list[list[Any]]:
419431
raw_sql = f"""
420432
SELECT
421433
json_build_object(
422-
{', '.join([f"'{i}', {sql}" for i, sql in enumerate(non_empty_django_sqls_for_querysets)])}
434+
{", ".join([f"'{i}', {sql}" for i, sql in enumerate(non_empty_django_sqls_for_querysets)])}
423435
)
424436
"""
425437
with connections["default"].cursor() as cursor:

pyproject.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "django-querysets-single-query-fetch"
7-
version = "0.0.12"
7+
version = "0.0.13"
88
description = "Execute multiple Django querysets in a single SQL query"
99
readme = "README.md"
1010
requires-python = ">=3.9"
@@ -30,8 +30,7 @@ classifiers = [
3030
"Topic :: Software Development :: Libraries :: Python Modules",
3131
]
3232
dependencies = [
33-
"django>=4.0,<5.2", # From setup.py
34-
"psycopg2==2.9.9" # Keep specific version for now
33+
"django>=4.0,<5.3", # Updated to include Django 5.2
3534
]
3635

3736
[project.urls]

testproject/settings.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@
7878
DATABASES = {
7979
"default": {
8080
"ENGINE": "django.db.backends.postgresql",
81-
"NAME": "testdb",
81+
"NAME": "sqf-db",
8282
"USER": "postgres",
8383
"PASSWORD": "postgres",
8484
"HOST": os.environ.get("DEFAULT_DB_HOST") or "localhost",
8585
"PORT": "5432",
86+
"TEST": {
87+
"NAME": "sqf-db-test",
88+
},
8689
}
8790
}
8891

0 commit comments

Comments
 (0)