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

Do not raise local OPTIMADE warnings at server level #1718

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions optimade/server/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from optimade.server.routers.utils import BASE_URL_PREFIXES, get_base_url
from optimade.warnings import (
FieldValueNotRecognized,
LocalOptimadeWarning,
OptimadeWarning,
QueryParamNotUsed,
TooManyValues,
Expand Down Expand Up @@ -361,6 +362,9 @@ def showwarning(
warnings._showwarning_orig(message, category, filename, lineno, file, line) # type: ignore[attr-defined]
return

if isinstance(message, LocalOptimadeWarning):
return

# Format warning
try:
title = str(message.title)
Expand Down
8 changes: 7 additions & 1 deletion optimade/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def __str__(self) -> str:
return self.detail if self.detail is not None else ""


class LocalOptimadeWarning(OptimadeWarning):
"""A warning that is specific to a local implementation of the OPTIMADE API
and should not appear in the server log or response.
"""


class FieldValueNotRecognized(OptimadeWarning):
"""A field or value used in the request is not recognised by this implementation."""

Expand All @@ -57,7 +63,7 @@ class QueryParamNotUsed(OptimadeWarning):
"""A query parameter is not used in this request."""


class MissingExpectedField(OptimadeWarning):
class MissingExpectedField(LocalOptimadeWarning):
"""A field was provided with a null value when a related field was provided
with a value."""

Expand Down