Django / psycopg2 / postgresql 可能损坏的模型给出无用的堆栈跟踪
我正在致力于将 OpenID 与我自己的 Django 身份验证堆栈集成。我正在使用 python-openid、django 1.2.5 和 postgresql,按照 examples/
下 djopenid 文件夹中的示例进行操作,
发生的情况是这样的。我正在使用一个调用 python-openid 的各种机制的视图,这些机制依赖于我输入的模型。其中的某个地方出现了问题。我的问题不是为什么它坏了,而是我无法告诉什么坏了。我的模型是直接根据他们的实现注释编写的,但我可能犯了一两个错误。
这是堆栈跟踪:
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
所以我了解 django 正在使用 postgresql 事务管理,并且在此过程中的某个地方我正在做一些导致数据库完整性问题的事情。但它没有告诉我这可能是什么,或者我的代码中的错误在哪里。我已经尝试将其在 settings.py
中关闭,看看是否会产生更合理的堆栈跟踪结果。事实并非如此。
我的问题很简单:如何找出问题出在哪里?我可以从有问题的 SQL 语句开始向后工作(因为这会告诉我哪些模型失败了),甚至更好的是涉及我的一些代码的堆栈跟踪。甚至“postgresql错误代码XYZ”也给了我一些谷歌的东西。我可以打开一些设置让 django 更加健谈吗?我正在使用
DEBUG = True
TEMPLATE_DEBUG = DEBUG
显然,但我什至没有收到黄色错误页面。只是普通的旧 500 内部服务器错误和 apache 错误日志中的堆栈跟踪。还有其他地方我可以看吗?我可以制定一些选项,或者一些我可以用来观察执行情况的巧妙工具?
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 Server 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过在某个端口上的 manage.py 运行它,将 ipdb.set_trace() 调用放在您的视图中并逐步跟踪它 - 就像在任何其他调试过程中一样。
您也可以使用 内置 python/django 日志记录功能 并只需打印我们的东西到日志文件中。
请参阅此处了解更多提示 - 也许其中一些对您有用。
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.