3 | | A developer can selectively silence warnings using something like this in an app's `AppConfig.ready()` method: |
4 | | {{{ |
5 | | import warnings |
6 | | from django.utils.deprecation import RemovedInNextVersionWarning |
7 | | warnings.simplefilter("ignore", RemovedInNextVersionWarning) |
8 | | }}} |
9 | | This example can be improved to show how to silence a particular warning instead of all warnings. |
| 3 | However, this idea is slightly flawed given our current deprecation scheme. If a third-party library wants to support both 1.8 and 1.11 (next LTS) would have to use a try (new import)/except (old import) pattern to avoid code running on 1.11 from raising deprecation warnings (some pending deprecation in 1.10, deprecated in 1.11, and removed in 2.0). In my mind, part of the purpose of the new policy was to avoid this type of complexity. |
11 | | This works because `AppConfig.ready()` methods are called after `django.utils.log.configure_logging()` (which does `warnings.simplefilter("default", RemovedInNextVersionWarning)`) in `django.setup()`. |
| 5 | For that reason, I think we should reconsider making Django's deprecation warnings loud by default (at least in LTS versions). Otherwise, users will pester library authors to fix those warnings and we haven't really made things easier. |
| 6 | |
| 7 | Instead, the idea would be for library authors to continue using the deprecated APIs while supporting the LTS in which they are deprecated and the previous LTS. When the version of Django following the LTS is released, library authors can then drop support for all Django versions before the LTS, check their package with the LTS using python -Wd and make the deprecation warning fixes, then seamlessly add support for the next version of Django. |