Skip to content

Commit

Permalink
Fix checking supports_transaction in atomic blocks
Browse files Browse the repository at this point in the history
PR django-import-export#480 introduced proper handling of transactions during import, but with additional check if DB engine does support transactions.

When transaction is already in atomic block (for example by using `ATOMIC_REQUESTS` in Django DB conf) and `import_data` performs check if DB support transaction, in some cases (like MySQL), this check tries to call `set_autocommit`, which is forbidden in atomic block. This fix it not to use `supports_transaction` at all (it's not used in whole Django at all either, besides tests) - previously user receives `ImproperlyConfigured` exception - now `transaction.atomic` will go through silently (for example in MyISAM case) or raise another exception to user, but it'll work for all engines that support DB transactions when transaction block is already entered.
  • Loading branch information
Mateusz Kurek committed Dec 30, 2016
1 parent da2081f commit e0f4f97
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions import_export/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,7 @@ def import_data(self, dataset, dry_run=False, raise_errors=False,
if use_transactions is None:
use_transactions = self.get_use_transactions()

connection = connections[DEFAULT_DB_ALIAS]
supports_transactions = getattr(connection.features, "supports_transactions", False)

if use_transactions and not supports_transactions:
raise ImproperlyConfigured

using_transactions = (use_transactions or dry_run) and supports_transactions
using_transactions = use_transactions or dry_run

if using_transactions:
with transaction.atomic():
Expand Down

0 comments on commit e0f4f97

Please sign in to comment.