sql-serverdjangopyodbcfreetds

Could not change transaction status (0) (SQLSetConnectAttr)


We have a Django app connected to a remote SQL-server database.
I get an error when i try to do an update request on a database table :
[HY000] [FreeTDS][SQL Server]Could not change transaction status (0) (SQLSetConnectAttr).
I conclude that a similar request is still in progress and it blocks all my requests.
1/ The "autocommit" parameter is True.
2/ I tested :
connection.rollback()
This did not resolve the problem.
3/ I tried to do a live SQL query on the database.
My query returns no error.
It's a problem with Django or the libraries used.

Traceback :
/venv/src/django-pyodbc-azure/sql_server/pyodbc/base.pyc in
_set_autocommit(self, autocommit)
361 else:
362 self.connection.rollback()
--> 363 self.connection.autocommit = autocommit
364
365 def check_constraints(self, table_names=None):

Error: ('HY000', '[HY000] [FreeTDS][SQL Server]Could not change
transaction status (0) (SQLSetConnectAttr)')

Does someone have an idea ?


Solution

  • The problem is fixed.
    I remove the following line:

    if not ModelName.objects.filter(pk=instance.pk)
    

    My code :

    @receiver(pre_save, sender=ModelName)
    def model_name_pre_save(sender, instance, **kwargs):
        if not ModelName.objects.filter(pk=instance.pk):
            instance.field_name = value