Features: 1) Introduced distinct warning and error logging for specific exceptions in GraphQL middleware; 2) Added new exception types for enhanced validation handling.
Fixes: 1) Corrected indentation inconsistency in delete_never_ordered_products command; 2) Fixed improper formatting of log handler configurations. Extra: Adjusted logging to conform to best practices; amended middleware exception handling logic to improve code readability.
This commit is contained in:
parent
4ef06dd971
commit
a562591900
3 changed files with 22 additions and 16 deletions
|
|
@ -18,9 +18,7 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
size = options["size"]
|
size = options["size"]
|
||||||
while True:
|
while True:
|
||||||
batch_ids = list(
|
batch_ids = list(Product.objects.filter(orderproduct__isnull=True).values_list("pk", flat=True)[:size])
|
||||||
Product.objects.filter(orderproduct__isnull=True).values_list("pk", flat=True)[:size]
|
|
||||||
)
|
|
||||||
if not batch_ids:
|
if not batch_ids:
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from os import getenv
|
||||||
|
|
||||||
from constance import config
|
from constance import config
|
||||||
from django.contrib.auth.models import AnonymousUser
|
from django.contrib.auth.models import AnonymousUser
|
||||||
from django.core.exceptions import BadRequest, DisallowedHost
|
from django.core.exceptions import BadRequest, DisallowedHost, PermissionDenied, ValidationError
|
||||||
from django.http import HttpResponseForbidden
|
from django.http import HttpResponseForbidden
|
||||||
from django.middleware.common import CommonMiddleware
|
from django.middleware.common import CommonMiddleware
|
||||||
from django.middleware.locale import LocaleMiddleware
|
from django.middleware.locale import LocaleMiddleware
|
||||||
|
|
@ -95,13 +95,21 @@ class BlockInvalidHostMiddleware:
|
||||||
|
|
||||||
# noinspection PyShadowingBuiltins
|
# noinspection PyShadowingBuiltins
|
||||||
class GrapheneLoggingErrorsDebugMiddleware:
|
class GrapheneLoggingErrorsDebugMiddleware:
|
||||||
|
WARNING_ONLY_ERRORS = [
|
||||||
|
BadRequest,
|
||||||
|
PermissionDenied,
|
||||||
|
DisallowedHost,
|
||||||
|
ValidationError,
|
||||||
|
]
|
||||||
|
|
||||||
def resolve(self, next, root, info, **args):
|
def resolve(self, next, root, info, **args):
|
||||||
try:
|
try:
|
||||||
return next(root, info, **args)
|
return next(root, info, **args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Error occurred in GraphQL execution:", exc_info=True)
|
if e in self.WARNING_ONLY_ERRORS:
|
||||||
if bool(int(getenv("DEBUG"))):
|
logger.warning(str(e))
|
||||||
|
else:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
raise e
|
raise e
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ LOGGING = {
|
||||||
"handlers": [
|
"handlers": [
|
||||||
"console",
|
"console",
|
||||||
"mail_admins",
|
"mail_admins",
|
||||||
],
|
],
|
||||||
"level": "DEBUG" if DEBUG else "INFO",
|
"level": "DEBUG" if DEBUG else "INFO",
|
||||||
"propagate": True,
|
"propagate": True,
|
||||||
},
|
},
|
||||||
|
|
@ -78,7 +78,7 @@ LOGGING = {
|
||||||
"handlers": [
|
"handlers": [
|
||||||
"console",
|
"console",
|
||||||
"mail_admins",
|
"mail_admins",
|
||||||
],
|
],
|
||||||
"level": "WARNING",
|
"level": "WARNING",
|
||||||
"propagate": False,
|
"propagate": False,
|
||||||
},
|
},
|
||||||
|
|
@ -86,7 +86,7 @@ LOGGING = {
|
||||||
"handlers": [
|
"handlers": [
|
||||||
"console",
|
"console",
|
||||||
"mail_admins",
|
"mail_admins",
|
||||||
],
|
],
|
||||||
"level": "DEBUG" if DEBUG else "ERROR",
|
"level": "DEBUG" if DEBUG else "ERROR",
|
||||||
"propagate": True,
|
"propagate": True,
|
||||||
"filters": ["skip_variable_doesnotexist"],
|
"filters": ["skip_variable_doesnotexist"],
|
||||||
|
|
@ -94,42 +94,42 @@ LOGGING = {
|
||||||
"gunicorn.access": {
|
"gunicorn.access": {
|
||||||
"handlers": [
|
"handlers": [
|
||||||
"console",
|
"console",
|
||||||
],
|
],
|
||||||
"level": "DEBUG" if DEBUG else "INFO",
|
"level": "DEBUG" if DEBUG else "INFO",
|
||||||
"propagate": False,
|
"propagate": False,
|
||||||
},
|
},
|
||||||
"gunicorn.error": {
|
"gunicorn.error": {
|
||||||
"handlers": [
|
"handlers": [
|
||||||
"console",
|
"console",
|
||||||
],
|
],
|
||||||
"level": "DEBUG" if DEBUG else "INFO",
|
"level": "DEBUG" if DEBUG else "INFO",
|
||||||
"propagate": False,
|
"propagate": False,
|
||||||
},
|
},
|
||||||
"django_elasticsearch_dsl": {
|
"django_elasticsearch_dsl": {
|
||||||
"handlers": [
|
"handlers": [
|
||||||
"console",
|
"console",
|
||||||
],
|
],
|
||||||
"level": "WARNING",
|
"level": "WARNING",
|
||||||
"propagate": False,
|
"propagate": False,
|
||||||
},
|
},
|
||||||
"celery.app.trace": {
|
"celery.app.trace": {
|
||||||
"handlers": [
|
"handlers": [
|
||||||
"console",
|
"console",
|
||||||
],
|
],
|
||||||
"level": "DEBUG" if DEBUG else "INFO",
|
"level": "DEBUG" if DEBUG else "INFO",
|
||||||
"propagate": False,
|
"propagate": False,
|
||||||
},
|
},
|
||||||
"celery.worker.strategy": {
|
"celery.worker.strategy": {
|
||||||
"handlers": [
|
"handlers": [
|
||||||
"console",
|
"console",
|
||||||
],
|
],
|
||||||
"level": "DEBUG" if DEBUG else "INFO",
|
"level": "DEBUG" if DEBUG else "INFO",
|
||||||
"propagate": False,
|
"propagate": False,
|
||||||
},
|
},
|
||||||
"elastic_transport.transport": {
|
"elastic_transport.transport": {
|
||||||
"handlers": [
|
"handlers": [
|
||||||
"console",
|
"console",
|
||||||
],
|
],
|
||||||
"level": "ERROR",
|
"level": "ERROR",
|
||||||
"propagate": False,
|
"propagate": False,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue