django / postgres:事务管理块以挂起的COMMIT / ROLLBACK结束

时间:2011-08-12 15:28:51

标签: django postgresql psycopg2

我想运行manage.py sqldiff myapp(来自django扩展名的命令),但是我收到以下错误:

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django_extensions/management/commands/sqldiff.py", line 596, in handle
    sqldiff_instance.find_differences()
  File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 222, in inner
    self.__exit__(None, None, None)
  File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 207, in __exit__
    self.exiting(exc_value, self.using)
  File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 302, in exiting
    leave_transaction_management(using=using)
  File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 56, in leave_transaction_management
    connection.leave_transaction_management()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in leave_transaction_management
    raise TransactionManagementError("Transaction managed block ended with "
django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK

manage.py runserver,shell,shell_plus都运行正常,但是sqldiff命令会阻塞。我试过了:

  
      
  • 重新启动postgres服务器
  •   
  • 通过psycopg2从shell手动连接到postgres,运行   connection.rollback()和connection.commit()
  •   

但错误仍然存​​在。

欢迎任何关于可以做什么的想法!

干杯,

霍夫

1 个答案:

答案 0 :(得分:2)

我使用sqldiff更新了issue,导致类似的问题。你最好的选择可能是从github repository获得django-extensions并进行一些调查。修改 sqldiff.py 并注释掉装饰 find_differences 方法的交易代码:

#    @transaction.commit_manually
def find_differences(self):
...
#                transaction.rollback()  # reset transaction
...
#                transaction.commit()

现在应该揭示您的真正问题,不再被事务异常掩盖。