From 37cc332fc3682cd88287e7d9bbe825587c3ed66f Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Sat, 22 Jul 2023 11:56:34 +0100 Subject: [PATCH] Do not raise local OPTIMADE warnings at server level --- optimade/server/middleware.py | 4 ++++ optimade/warnings.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/optimade/server/middleware.py b/optimade/server/middleware.py index 68fc8f2fa4..64cb44f906 100644 --- a/optimade/server/middleware.py +++ b/optimade/server/middleware.py @@ -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, @@ -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) diff --git a/optimade/warnings.py b/optimade/warnings.py index 4fea44be96..c715936d5a 100644 --- a/optimade/warnings.py +++ b/optimade/warnings.py @@ -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.""" @@ -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."""