Request exceptions have always been easy to manage, because you can use 
middleware, and there is the built-in signal: 
https://docs.djangoproject.com/en/3.0/ref/signals/#got-request-exception

Problem:

However, if you want to send data to e.g., Sentry or perform some other 
action (logging, etc.) upon any Django management command error, there 
aren't built-in facilities to deal with this. Even writing your own command 
base class won't suffice, because that won't cover built-in or third-party 
commands.

Solution:

I propose a "got_command_exception" signal, which would operate similarly 
to "got_request_exception", except that it would pass in the management 
command class instance as the `sender`, and the provided args/kwargs. Being 
run inside of the exception handler would allow for logging.exception(...) 
and other exc_info needs.


Due to the fact that all commands run through the same call_command 
infrastructure, I think this is a good approach to solving the problem I 
described.

If a majority of folks think this is a good approach, I'll make a patch.

Thoughts?

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/f1950d49-c938-41a3-b93d-066ef387a54a%40googlegroups.com.

Reply via email to