How to inject pdb into unsuccessful python scripts?

I am working on a django project that has a great tool that doesn't load:

$ python manage.py loaddata apps/mainsite/fixtures/test_auctions.json /Users/cp/bidsite/.ve/lib/python2.6/site-packages/django/db/models/fields/subclassing.py:80: DeprecationWarning: A Field class whose get_db_prep_save method hasn't been updated to take a `connection` argument. new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs) /Users/cp/bidsite/.ve/lib/python2.6/site-packages/django/db/models/fields/subclassing.py:80: DeprecationWarning: A Field class whose get_db_prep_lookup method hasn't been updated to take `connection` and `prepared` arguments. new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs) /Users/cp/bidsite/.ve/lib/python2.6/site-packages/celery/task/schedules.py:5: DeprecationWarning: celery.task.schedules is deprecated and renamed to celery.schedules "celery.task.schedules is deprecated and renamed to celery.schedules")) Problem installing fixture 'apps/mainsite/fixtures/test_auctions.json': Traceback (most recent call last): File "/Users/cp/bidsite/.ve/lib/python2.6/site-packages/django/core/management/commands/loaddata.py", line 174, in handle obj.save(using=using) File "/Users/cp/bidsite/.ve/lib/python2.6/site-packages/django/core/serializers/base.py", line 165, in save models.Model.save_base(self.object, using=using, raw=True) File "/Users/cp/bidsite/.ve/lib/python2.6/site-packages/django/db/models/base.py", line 570, in save_base created=(not record_exists), raw=raw, using=using) File "/Users/cp/bidsite/.ve/lib/python2.6/site-packages/django/dispatch/dispatcher.py", line 172, in send response = receiver(signal=self, sender=sender, **named) File "/Users/cp/bidsite/apps/mainsite/models.py", line 257, in update_auction_details auction_json = instance.as_json() File "/Users/cp/bidsite/apps/mainsite/models.py", line 1110, in as_json 'product': self.product.as_json(), File "/Users/cp/bidsite/.ve/lib/python2.6/site-packages/django/db/models/fields/related.py", line 315, in __get__ rel_obj = QuerySet(self.field.rel.to).using(db).get(**params) File "/Users/cp/bidsite/.ve/lib/python2.6/site-packages/django/db/models/query.py", line 349, in get % self.model._meta.object_name) DoesNotExist: Product matching query does not exist. 

The problem is that stacktrace does not let me know which line on the device is causing this error. How can I debug this? The only thing I can come up with is the ipythgon function, where whenever you execute something and an exception occurs, ipython automatically enters the pdb hint so you can get closer to find out what happened. How can I do this with this? Is there a command line switch for python that does this? What can I do here to debug this?

+4
source share
1 answer

In this Python recipe, a debugger will be installed, starting with uncaught exceptions:

http://code.activestate.com/recipes/65287-automatically-start-the-debugger-on-an-exception/

Its essence is to set an exception hook in sys.excepthook, which calls pdb.pm () when called (although this is a bit more complicated than that).

+6
source

Source: https://habr.com/ru/post/1338279/


All Articles