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

fix: Remove overwriting action from @deprecated decorator #1389

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

sveneberth
Copy link
Member

The deprecations warnings on third party packages
(which are still in compatibility mode with 3.6) are getting annoying. Therefore I have set up the following warning filter in my project:

    warnings.filterwarnings("ignore", category=DeprecationWarning, module=r"viur\.(shop|toolkit).*",
                            message="'clonedBoneMap' was renamed into 'bone_map'")
    warnings.filterwarnings("ignore", category=DeprecationWarning, module=r"viur\.(shop|toolkit).*",
                            message=r"Call to deprecated class method (subSkel|fromDB|toDB)")

Unfortunately it does not work, because the deprecations in the skeleton module are explicitly called with an action parameter. This in turn means that these warnings are executed in a separate context with exactly this action, all other filter conditions are overwritten or ignored.

I therefore suggest setting the general filter in the __init__ to "once".

The module filter was wrong at this point anyway. The module refers to the module that calls the deprecated method,
not the one that triggers the warning (my fault).

This general filter can easily be customized from a relaxed "ignore" to an annoying "always" in the project.

Alternatively, the viur-core could also use its own DeprecationWarning subclass so that these warnings could be filtered even more finely using the class filter.

The deprecations warnings on third party packages
(which are still in compatibility mode with 3.6) are getting annoying.
Therefore I have set up the following warning filter in my project:

```py
    warnings.filterwarnings("ignore", category=DeprecationWarning, module=r"viur\.(shop|toolkit).*",
                            message="'clonedBoneMap' was renamed into 'bone_map'")
    warnings.filterwarnings("ignore", category=DeprecationWarning, module=r"viur\.(shop|toolkit).*",
                            message=r"Call to deprecated class method (subSkel|fromDB|toDB)")
```

Unfortunately it does not work, because the deprecations in the `skeleton` module
are explicitly called with an `action `parameter. This in turn means that
these warnings are executed in a separate context with exactly this action,
all other filter conditions are overwritten or ignored.

I therefore suggest setting the general filter in the `__init__` to `"once"`.

The module filter was wrong at this point anyway. The `module` refers
to the module that calls the deprecated method,
not the one that triggers the warning (my fault).

This general filter can easily be customized from a relaxed `"ignore"`
to an annoying `"always"` in the project.

Alternatively, the `viur-core` could also use its own `DeprecationWarning` subclass
so that these warnings could be filtered even more finely using the
class filter.
@sveneberth sveneberth added bug(fix) Something isn't working or address a specific issue or vulnerability Priority: Medium This issue may be useful, and needs some attention. annoying labels Jan 25, 2025
@phorward phorward merged commit 9fc6dad into viur-framework:main Jan 28, 2025
3 checks passed
@sveneberth sveneberth deleted the fix/controllable_warnings branch January 29, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annoying bug(fix) Something isn't working or address a specific issue or vulnerability Priority: Medium This issue may be useful, and needs some attention.
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants