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

发布于 2024-11-29 13:28:09 字数 2112 浏览 1 评论 0原文

我想运行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,运行 连接.rollback() 和连接.commit()

但错误仍然存​​在。

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

干杯,

霍夫

I want to run manage.py sqldiff myapp (command from django extension), but I get the following error:

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 all work fine, but the sqldiff command chokes. I have tried:

  • restart postgres server
  • manually connect to postgres from shell via psycopg2, ran
    connection.rollback(), and connection.commit()

but the error persists.

Any ideas on what can be done are welcome!

Cheers,

Hoff

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謌踐踏愛綪 2024-12-06 13:28:09

我更新了 问题,sqldiff 导致了类似的问题。您最好的选择可能是从 github 存储库 获取 django-extensions 并执行一些操作调查。编辑sqldiff.py并注释掉装饰find_differences方法的事务代码:

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

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

I updated an issue with sqldiff causing similar problems. Your best bet is probably to obtain django-extensions from the github repository and do a bit of investigation. Edit sqldiff.py and comment out the transaction code decorating the find_differences method:

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

Now your real problem should be revealed, no longer masked by the transaction exception.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文