Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Enable psycopg v3 tests #685

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
57 changes: 50 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,84 @@ jobs:
django-version:
- 4.2.*
- 5.0.*
- 5.1.*
python-version:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
mode:
- std
- geos
psycopg:
- "psycopg2"
- "psycopg" # v3
include:
# Django 4.2 only supports python 3.8-3.12
- django-version: 4.2.*
python-version: "3.8"
mode: std
psycopg: psycopg2
- django-version: 4.2.*
python-version: "3.8"
mode: geos
psycopg: psycopg2
# Python 3.8 requires psycopg<3.3
# Ref: https://www.psycopg.org/psycopg3/docs/basic/install.html#supported-systems
- django-version: 4.2.*
python-version: "3.8"
mode: std
psycopg: "psycopg==3.2"
- django-version: 4.2.*
python-version: "3.8"
mode: geos
psycopg: "psycopg==3.2"
exclude:
# Django 5.0 only supports python 3.10+
# Django 4.2 only supports python 3.8-3.12
- django-version: 4.2.*
python-version: "3.13"
# Django 5.0 only supports python 3.10-3.12
- django-version: 5.0.*
python-version: '3.9'
python-version: "3.9"
- django-version: 5.0.*
python-version: "3.13"
# Django 5.1 only supports python 3.10+
- django-version: 5.1.*
python-version: "3.9"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install OS Dependencies
if: ${{ matrix.mode == 'geos' }}
uses: daaku/gh-action-apt-install@v4
with:
packages: binutils gdal-bin libproj-dev libsqlite3-mod-spatialite

- name: Install Poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
with:
cache: poetry
python-version: ${{ matrix.python-version }}

- name: Install Deps
run: poetry install

- name: Install ${{ matrix.psycopg }}
run: |
poetry run pip install "${{ matrix.psycopg }}"

- name: Install Django ${{ matrix.django-version }}
run: poetry run pip install "django==${{ matrix.django-version }}"

- name: Test with pytest
run: poetry run pytest --showlocals -vvv --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
env:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: check-xml
- id: check-symlinks
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
rev: v0.8.4
hooks:
- id: ruff-format
- id: ruff
Expand Down
50 changes: 15 additions & 35 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ asgiref = ">=3.8"
django-choices-field = { version = ">=2.2.2", optional = true }
django-debug-toolbar = { version = ">=3.4", optional = true }
strawberry-graphql = ">=0.236.0"
django-tree-queries = "^0.19.0"

[tool.poetry.group.dev.dependencies]
channels = { version = ">=3.0.5" }
django-choices-field = "^2.2.2"
django-debug-toolbar = "^4.4.6"
django-guardian = "^2.4.0"
django-mptt = "^0.14.0"
django-types = "^0.20.0"
factory-boy = "^3.2.1"
pillow = "^11.0.0"
Expand Down Expand Up @@ -132,7 +132,7 @@ extend-ignore = [
"TRY003",
"PLR6301",
"PLC0415",
"TCH002",
"TC002",
# ruff formatter recommends to disable those
"COM812",
"COM819",
Expand Down
2 changes: 1 addition & 1 deletion strawberry_django/fields/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
try:
from django.contrib.postgres.fields import ArrayField
except (ImportError, ModuleNotFoundError): # pragma: no cover
# ArrayField will not be importable if psycopg2 is not installed
# ArrayField will not be importable if psycopg or psycopg2 is not installed
ArrayField = None

if django.VERSION >= (5, 0):
Expand Down
25 changes: 0 additions & 25 deletions tests/relay/mptt/a.py

This file was deleted.

32 changes: 0 additions & 32 deletions tests/relay/mptt/b.py

This file was deleted.

File renamed without changes.
25 changes: 25 additions & 0 deletions tests/relay/treenode/a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import TYPE_CHECKING, Annotated

import strawberry
from strawberry import relay
from typing_extensions import TypeAlias

import strawberry_django
from strawberry_django.relay import ListConnectionWithTotalCount

from .models import TreeNodeAuthor

if TYPE_CHECKING:
from .b import TreeNodeBookConnection


@strawberry_django.type(TreeNodeAuthor)
class TreeNodeAuthorType(relay.Node):
name: str
books: Annotated[
"TreeNodeBookConnection", strawberry.lazy("tests.relay.treenode.b")
] = strawberry_django.connection()
children: "TreeNodeAuthorConnection" = strawberry_django.connection()


TreeNodeAuthorConnection: TypeAlias = ListConnectionWithTotalCount[TreeNodeAuthorType]
34 changes: 34 additions & 0 deletions tests/relay/treenode/b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import TYPE_CHECKING, Annotated

import strawberry
from strawberry import relay
from typing_extensions import TypeAlias

import strawberry_django
from strawberry_django.relay import ListConnectionWithTotalCount

from .models import TreeNodeBook

if TYPE_CHECKING:
from .a import TreeNodeAuthorType


@strawberry_django.filter(TreeNodeBook)
class TreeNodeBookFilter:
name: str


@strawberry_django.order(TreeNodeBook)
class TreeNodeBookOrder:
name: str


@strawberry_django.type(
TreeNodeBook, filters=TreeNodeBookFilter, order=TreeNodeBookOrder
)
class TreeNodeBookType(relay.Node):
name: str
author: Annotated["TreeNodeAuthorType", strawberry.lazy("tests.relay.treenode.a")]


TreeNodeBookConnection: TypeAlias = ListConnectionWithTotalCount[TreeNodeBookType]
12 changes: 6 additions & 6 deletions tests/relay/mptt/models.py → tests/relay/treenode/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.db import models
from mptt.fields import TreeForeignKey
from mptt.models import MPTTModel
from tree_queries.fields import TreeNodeForeignKey
from tree_queries.models import TreeNode


class MPTTAuthor(MPTTModel):
class TreeNodeAuthor(TreeNode):
name = models.CharField(max_length=100)
parent = TreeForeignKey(
parent = TreeNodeForeignKey(
to="self",
on_delete=models.CASCADE,
null=True,
Expand All @@ -14,10 +14,10 @@ class MPTTAuthor(MPTTModel):
)


class MPTTBook(models.Model):
class TreeNodeBook(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(
MPTTAuthor,
TreeNodeAuthor,
on_delete=models.CASCADE,
related_name="books",
)
Loading
Loading