开发者

Django / psycopg2 / postgresql probably broken models give useless stack trace

开发者 https://www.devze.com 2023-02-13 09:57 出处:网络
I\'m working on integrating OpenID with my own authentication Stack for Django. I\'m using python-openid, django 1.2.5 with postgresql, following the examples from the djopenid folder under examples/

I'm working on integrating OpenID with my own authentication Stack for Django. I'm using python-openid, django 1.2.5 with postgresql, following the examples from the djopenid folder under examples/

What's happening is this. I'm using a view that calls python-openid's various mechanisms, which rely on models I've fed in. Somewhere in there, something's breaking. My problem is not why it is broken, it is the fact that I can't tell what is broken. My models are written directly against their implementation comments, but I have probably made a mistake or two.

This is the stack trace:

mod_wsgi (pid=5476): Exception occurred processing WSGI script 
'/var/www/Django/Testbed/Testbed.wsgi'., referer: 
http://localhost/testbed/openidlogin
 Traceback (most recent call last):, referer: 
http://localhost/testbed/openidlogin
   File "/usr/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 
252, in __call__, referer: http://localhost/testbed/openidlogin
     response = middleware_method(request, response), referer: 
http://localhost/testbed/openidlogin
   File 
"/usr/lib/python2.7/site-packages/django/contrib/sessions/middleware.py", line 
36, in process_response, referer: http://localhost/testbed/openidlogin
     request.session.save(), referer: http://localhost/testbed/openidlogin
   File 
"/usr/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py", line 
61, in save, referer: http://localhost/testbed/openidlogin
     sid = transaction.savepoint(using=using), referer: 
http://localhost/testbed/openidlogin
   File "/usr/lib/python2.7/site-packages/django/db/transaction.py", line 229, 
in savepoint, referer: http://localhost/testbed/openidlogin
     connection._savepoint(sid), referer: http://localhost/testbed/openidlogin
   File "/usr/lib/python2.7/site-packages/django/db/backends/__init__.py", line 
56, in _savepoint, referer: http://localhost/testbed/openidlogin
     self.cursor().execute(self.ops.savepoint_create_sql(sid)), referer: 
http://localhost/testbed/openidlogin
   File "/usr/lib/python2.7/site-packages/django/db/backends/util.py", line 15, 
in execute, referer: http://localhost/testbed/openidlogin
     return self.cursor.execute(sql, params), referer: 
http://localhost/testbed/openidlogin
   File 
"/usr/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py
", line 44, in execute, referer: http://localhost/testbed/openidlogin
     return self.cursor.execute(query, args), referer: 
http://localhost/testbed/openidlogin
 DatabaseError: current transaction is aborted, commands ignored until end of 
transaction block, referer: http://localhost/testbed/openidlogin

So I understand django is using postgresql transaction management and that somewhere in this process I'm doing something that causes an integrity issue with the database. But it doesn't tell me what that might be, or where the error is in my code. I've tried turning this off in settings.py to see if a more sensible stack trace results. It doesn't.

My question is very simple: How do I find out where the problem is? I can work backwards from an offending SQL statement (since that will tell me which models are failing) or even better a stack trace involving some of my code. Even "postgresql error code XYZ" gives me something to google. Are there some settings I can turn on that make django a little more talkative? I'm using

DEBUG = True
TEMPLATE_DEBUG = DEBUG

Obviously, but I'm not even getting a yellow error page. Just your plain old 500 Internal Ser开发者_如何学编程ver Error and that stack trace in the error log of apache. Is there somewhere else I can look? Some option I can enact or some whizzy tool that I can use to watch execution or something?


Run it via manage.py on some port, place ipdb.set_trace() call in your view and trace it step by step - like in any other debugging process.

Also you can use built-in python/django logging features and just print our stuff to the log file.

Look here for more tips - maybe some of them will be usefull for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消