开发者

django/postgres: Transaction managed block ended with pending COMMIT/ROLLBACK

开发者 https://www.devze.com 2023-03-28 05:54 出处:网络
I want to run manage.py sqldiff myapp (command from django extension), but I get the following error:

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 wha开发者_开发知识库t can be done are welcome!

Cheers,

Hoff


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.

0

精彩评论

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

关注公众号