Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with transaction.atomic() not working for Azure SQL Database #208

Open
RRaideRR opened this issue Aug 1, 2019 · 2 comments
Open

with transaction.atomic() not working for Azure SQL Database #208

RRaideRR opened this issue Aug 1, 2019 · 2 comments

Comments

@RRaideRR
Copy link

RRaideRR commented Aug 1, 2019

I use django-pyodbc-azure 2.1.0.0 for the connection with an Azure SQL database which works fine.

When I understand the documentation of django-pyodbc-azure correctly, transactions should be supported.

However, this code immediately updates the row. I would expect, that the row is updated after 20 seconds.

from django.db import transaction
from myapp.models import MyModel
import time

with transaction.atomic():
    MyModel.objects.filter(id=1).update(my_field='Test')
    time.sleep(20)

Am I doing something wrong? Do I need to specifiy certain settings on the Azure SQL database?

My current settings.py

'azure_reporting': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'reporting_db',
    'HOST': 'xxxxxx.database.windows.net',
    'PORT': '',
    'USER': 'xxxx@xxxxxx.database.windows.net',
    'PASSWORD': 'xxxxxx',

    'OPTIONS': {
        'driver': 'ODBC Driver 17 for SQL Server'
    }
}
@soasuk
Copy link

soasuk commented Sep 11, 2019

I found something similar with 2.1.0.0 when doing migrations. My migration had several steps, a later one failed and instead of rolling all steps back, the previous steps were still applied. An output of the SQL produced something like this:

BEGIN TRANSACTION
**alter table steps
COMMIT;

Running the same SQL directly in management studio produced the same failed step as via migrate, however all the previous steps were rolled back as expected.

@sandipbgt
Copy link

sandipbgt commented Dec 11, 2019

depending upon name of connections dictionary in settings.py
try like this:

with transaction.atomic(using='azure_reporting'):
	MyModel.objects.filter(id=1).update(my_field='Test')
	time.sleep(20)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants