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

Django 3 #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
language: python
sudo: false
python:
- "2.7"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
env:
global:
- PYTHONPATH=tests/testapp
matrix:
- DJANGO_VERSION=">=1.8,<1.9"
- DJANGO_VERSION=">=1.9,<1.10"
- DJANGO_VERSION=">=1.10,<1.11"
- DJANGO_VERSION=">=1.11,<2.0"
- DJANGO_VERSION=">=2.0,<2.1"
- DJANGO_VERSION=">=2.1,<2.2"
matrix:
exclude:
- python: "2.7"
env: DJANGO_VERSION=">=2.0,<2.1"
- python: "2.7"
env: DJANGO_VERSION=">=2.1,<2.2"
- DJANGO_VERSION=">=2.2,<3.0"
- DJANGO_VERSION=">=3.1,<3.2"
- DJANGO_VERSION=">=3.2,<4.0"
install:
- travis_retry pip install codecov
- travis_retry pip install -U -r dev-requirements.txt
Expand Down
5 changes: 1 addition & 4 deletions nplusone/ext/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

from django.conf import settings

try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
MiddlewareMixin = object
from django.utils.deprecation import MiddlewareMixin

from nplusone.core import listeners
from nplusone.core import notifiers
Expand Down
39 changes: 9 additions & 30 deletions nplusone/ext/django/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@
import importlib
import threading

import django
from django.db.models import query
from django.db.models import Model

from nplusone.core import signals

if django.VERSION >= (1, 9): # pragma: no cover
from django.db.models.fields.related_descriptors import (
ReverseOneToOneDescriptor,
ForwardManyToOneDescriptor,
create_reverse_many_to_one_manager,
create_forward_many_to_many_manager,
)
else: # pragma: no cover
from django.db.models.fields.related import (
SingleRelatedObjectDescriptor as ReverseOneToOneDescriptor,
ReverseSingleRelatedObjectDescriptor as ForwardManyToOneDescriptor,
create_foreign_related_manager as create_reverse_many_to_one_manager,
create_many_related_manager as create_forward_many_to_many_manager,
)
from django.db.models.fields.related_descriptors import (
ReverseOneToOneDescriptor,
ForwardManyToOneDescriptor,
create_reverse_many_to_one_manager,
create_forward_many_to_many_manager,
)


def get_worker():
Expand Down Expand Up @@ -88,16 +79,8 @@ def get_related_name(model):

def parse_field(field):
return (
(
field.related_model # Django >= 1.8
if hasattr(field, 'related_model')
else field.related_field.model # Django <= 1.8
),
(
field.remote_field.name # Django >= 1.8
if hasattr(field, 'remote_field')
else field.rel.related_name # Django <= 1.8
) or get_related_name(field.related_model),
field.related_model,
field.remote_field.name or get_related_name(field.related_model),
)


Expand Down Expand Up @@ -142,11 +125,7 @@ def parse_many_related_queryset(args, kwargs, context):
rel = context['rel']
manager = context['args'][0]
model = manager.instance.__class__
related_model = (
manager.target_field.related_model # Django >= 1.8
if hasattr(manager.target_field, 'related_model')
else manager.target_field.related_field.model # Django <= 1.8
)
related_model = manager.target_field.related_model
field = manager.prefetch_cache_name if rel.related_name else None
return (
model,
Expand Down
10 changes: 5 additions & 5 deletions nplusone/ext/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

def to_key(instance):
model = type(instance)
return ':'.join(
[model.__name__] +
[
return ':'.join(itertools.chain(
[model.__name__],
(
format(instance.__dict__.get(key.key)) # Avoid recursion on __get__
for key in get_primary_keys(model)
]
)
)
))


def get_primary_keys(model):
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ universal=1
# E265: block comment should start with #
# E301: expected 1 blank line, found 1
# E302: expected 2 blank lines, found 0
# W504: line break after binary operator
[flake8]
ignore = E127,E128,E265,E301,E302,E305,E306
ignore = E127,E128,E265,E301,E302,E305,E306,W504
max-line-length = 90
11 changes: 4 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist={py27,py33,py34,py35,py36}-{django18,django19,django110,django111,django20,django21}
envlist={py37,py38,py39}-{django22,django31,django32}

[testenv]
deps=
Expand All @@ -19,12 +19,9 @@ deps=
peewee

; Django versions
django18: django>=1.8,<1.9
django19: django>=1.9,<1.10
django110: django>=1.10,<1.11
django111: django>=1.11,<2.0
django20: django>=2.0,<2.1
django21: django>=2.1,<2.2
django22: django>=2.2,<3.0
django31: django>=3.1,<3.2
django32: django>=3.2,<4.0
commands=
flake8 .
py.test