Skip to content

Commit a6975a4

Browse files
authored
Merge pull request #10 from ghazi-git/add-support-for-django-4.1
add-support-for-django-4.1
2 parents fa3bcdb + de7bbb4 commit a6975a4

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
## [UNRELEASED]
88
### Added
99
- add support for automatically generating error responses schema with [drf-spectacular](https://github.com/tfranzel/drf-spectacular).
10+
- add support for django 4.1
1011

1112
## [0.11.0] - 2022-06-24
1213
### Changed (Backward-incompatible)

drf_standardized_errors/handler.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from typing import Optional
33

4+
import django
45
from django.conf import settings
56
from django.core import signals
67
from django.core.exceptions import PermissionDenied
@@ -115,11 +116,21 @@ def report_exception(self, exc: exceptions.APIException, response):
115116
except AttributeError:
116117
request = None
117118
signals.got_request_exception.send(sender=None, request=request)
118-
log_response(
119-
"%s: %s",
120-
exc.detail,
121-
getattr(request, "path", ""),
122-
response=response,
123-
request=request,
124-
exc_info=sys.exc_info(),
125-
)
119+
if django.VERSION < (4, 1):
120+
log_response(
121+
"%s: %s",
122+
exc.detail,
123+
getattr(request, "path", ""),
124+
response=response,
125+
request=request,
126+
exc_info=sys.exc_info(),
127+
)
128+
else:
129+
log_response(
130+
"%s: %s",
131+
exc.detail,
132+
getattr(request, "path", ""),
133+
response=response,
134+
request=request,
135+
exception=exc,
136+
)

drf_standardized_errors/openapi_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dataclasses import field as dataclass_field
33
from typing import List, Optional, Set, Type, Union
44

5+
import django
56
from django import forms
67
from django.core.validators import (
78
DecimalValidator,
@@ -372,6 +373,11 @@ def get_error_codes_from_validators(
372373
EmailValidator,
373374
FileExtensionValidator,
374375
]
376+
if django.VERSION >= (4, 1):
377+
from django.core.validators import StepValueValidator
378+
379+
validators.append(StepValueValidator)
380+
375381
for validator in validators:
376382
if has_validator(field, validator):
377383
error_codes.add(validator.code)

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
isolated_build = True
88
envlist =
99
py{38,39,310}-dj32-drf{312,313}
10-
py{38,39,310}-dj40-drf313
10+
py{38,39,310}-dj{40,41}-drf313
1111
lint
1212
docs
1313

@@ -25,6 +25,7 @@ deps =
2525
django-filter
2626
dj32: Django>=3.2,<4.0
2727
dj40: Django>=4.0,<4.1
28+
dj41: Django>=4.1,<4.2
2829
drf312: djangorestframework>=3.12,<3.13
2930
drf313: djangorestframework>=3.13,<3.14
3031
commands =

0 commit comments

Comments
 (0)