Skip to content
Prev Previous commit
Next Next commit
Send deprecation note through warnings.warn() rather than the Django …
…logger
  • Loading branch information
alxbridge committed Jan 10, 2024
commit 3dd744c137839f5f3f2ac8e9c6b204e70e8e78db
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
### Changed

- Disable pointer events on menu chevron to allow clicks ([#202](https://github.com/torchbox/django-pattern-library/issues/202), [#205](https://github.com/torchbox/django-pattern-library/pull/205))
- From Django >= 4.0, calls to `Node.render()` must always return a string, but this app previously allowed non-string values to be passed in the `default_html` parameter to `override_tag`. Passing a non-string now raises a `TypeError` when using Django >= 4.0, and logs a warning for older versions ([issue #211](https://github.com/torchbox/django-pattern-library/issues/211)).
- From Django >= 4.0, calls to `Node.render()` must always return a string, but this app previously allowed non-string values to be passed in the `default_html` parameter to `override_tag`. Passing a non-string now raises a `TypeError` when using Django >= 4.0, and raises a warning for older versions ([issue #211](https://github.com/torchbox/django-pattern-library/issues/211)).

## [1.0.1](https://github.com/torchbox/django-pattern-library/releases/tag/v1.0.1) - 2023-08-19

Expand Down
12 changes: 5 additions & 7 deletions pattern_library/monkey_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import logging
import typing
import warnings

import django
from django.template.library import SimpleNode
Expand Down Expand Up @@ -88,13 +89,10 @@ def node_render(context):
# Ensure default_html is a string.
if not isinstance(default_html, str):
if django.VERSION < (4, 0):
logger.warning(
(
"default_html argument to override_tag should be a string to ensure compatibility "
'with Django >= 4.0 (line %s in "%s")'
),
trace.lineno,
trace.filename,
warnings.warn(
"default_html argument to override_tag should be a string to ensure compatibility "
'with Django >= 4.0 (line %s in "%s")' % (trace.lineno, trace.filename),
Warning,
)
else:
raise TypeError(
Expand Down