Skip to content

Commit

Permalink
Do not raise local OPTIMADE warnings at server level (#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Jul 22, 2023
1 parent b377447 commit d96e3a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit d96e3a8

Please sign in to comment.