... using = None ) [ソース] このデコレータは、与えられたビューのために ATOMIC_REQUESTS を無効化します。 from django.db import transaction @transaction . non_atomic_requests def my_view ( request ): do_stuff () @transaction . non_atomic_requests ( using = "othe ... ックの中に入れ子になっている場合、 RuntimeError が発生します。 atomic is usable both as a decorator : from django.db import transaction @transaction . atomic def viewfunc ( request ): # This code executes inside a transaction. do_stuff () and as a context ma ... nager : from django.db import transaction def viewfunc ( request ): # This code executes in autocommit mode (Django's default). do_stuff () with transaction . atomi ... ... u want to continue to use the base unittest library, you can -- you just won't get any of the nice new unittest2 features. Transaction context managers Users of Python 2.5 and above may now use transaction management functions as context managers. For examp ... le: with transaction . autocommit (): ... Configurable delete-cascade ForeignKey and OneToOneField now accept an on_delete argument to customiz ... also delete the file from the backend storage. This opened the door to several data-loss scenarios, including rolled-back transactions and fields on different models referencing the same file. In Django 1.3, when a model is deleted the FileField 's delete( ... ... faults to SQLite. If the default templates don't suit your tastes, you can use custom project and app templates . Improved transaction management Django's transaction management was overhauled. Database-level autocommit is now turned on by default. This mak ... es transaction handling more explicit and should improve performance. The existing APIs were deprecated, and new APIs were introduced, as ... described in the transaction management docs . Persistent database connections Django now supports reusing the same database connection for several req ... ... トランザクション For most backends, Tasks are run in a separate process, using a different database connection. When using a transaction, without waiting for it to commit, workers could start to process a Task which uses objects it can't access yet. For examp ... le, consider this simplified example: @task def my_task ( thing_num ): Thing . objects . get ( num = thing_num ) with transaction . atomic (): Thing . objects . create ( num = 1 ) my_task . enqueue ( thing_num = 1 ) To prevent the scenario where my_tas ... k runs before the Thing is committed to the database, use transaction.on_commit() , binding all arguments to enqueue() via functools.partial() : from functools import partial from django.db im ... ... django.db.models.functions.UUID4 is a cross-database version of this function. RandomUUID may be deprecated in the future. TransactionNow class TransactionNow [ソース] 現在のトランザクションが開始されたデータベースサーバー上の日時を返します。トランザクション ... tions.Now を補完するもので、現在のステートメントの日時を返します。 Note that only the outermost call to atomic() sets up a transaction and thus sets the time that TransactionNow() will return; nested calls create savepoints which do not affect the transacti ... on time. 使用例: >>> from django.contrib.postgres.functions import TransactionNow >>> Article . objects . filter ( published__lte = TransactionNow ()) <QuerySet [<Article: How to Django>]> ... ... , and Substr . TestCase data setup TestCase has been refactored to allow for data initialization at the class level using transactions and savepoints. Database backends which do not support transactions, like MySQL with the MyISAM storage engine, will stil ... ine for a given feature, its removal may appear as a backwards incompatible change. Related object operations are run in a transaction Some operations on related objects such as add() or direct assignment ran multiple data modifying queries without wrapping ... them in transactions. To reduce the risk of data corruption, all data modifying methods that affect multiple related objects (i.e. add() , rem ... ... 4-bit constraints, you will need to manually drop the old constraint prior to invoking reset . Test cases are now run in a transaction Django 1.1 runs tests inside a transaction, allowing better test performance (see test performance improvements for detail ... s). This change is slightly backwards incompatible if existing tests need to test transactional behavior, if they rely on invalid assumptions about the test environment, or if they require a specific test case orderi ... ng. For these cases, TransactionTestCase can be used instead. This is a just a quick fix to get around test case errors revealed by the new rollback approa ... ... rt for overriding ModelAdmin.get_action_choices() without the new action_location parameter will be removed. The django.db.transaction.savepoint() alias to django.db.transaction.savepoint_create() will be removed. Support for Model.from_db() methods that do ... eometryWidget の map_width と map_height 属性は削除されます。 SimpleTestCase.assertFormsetError() メソッドは削除されます。 TransactionTestCase.assertQuerysetEqual() メソッドは削除されます。 JSONField と関連するルックアップや式に対して、エンコードされた JSON ... EmailValidator の whitelist 引数と domain_whitelist 属性が削除されます。 default_app_config モジュール変数は削除されます。 TransactionTestCase.assertQuerysetEqual() は、文字列の値と比較する際に、クエリセットに対して自動的に repr() を呼び出すことはなくなりま ... ... e. LayerMapping API class LayerMapping ( model , data_source , mapping , layer = 0 , source_srs = None , encoding = None , transaction_mode = 'commit_on_success' , transform = True , unique = True , using = 'default' ) [ソース] 以下は LayerMapping オブジェク ... g of the strings in the OGR data source. For example, 'latin-1' , 'utf-8' , and 'cp437' are all valid encoding parameters. transaction_mode commit_on_success' (デフォルト) または 'autocommit' を指定します。 transform Setting this to False will disable coord ... given name(s). Geometries from each feature will be added into the collection associated with the unique model. Forces the transaction mode to be 'autocommit' . using 空間データをインポートする際に使用するデータベースを設定します。デフォルトは 'default' です ... ... tions class Migration ( migrations . Migration ): atomic = False Within such a migration, all operations are run without a transaction. It's possible to execute parts of the migration inside a transaction using atomic() or by passing atomic=True to RunPytho ... ーブルを小さなバッチで更新する、非アトミックなデータマイグレーションの例です: import uuid from django.db import migrations , transaction def gen_uuid ( apps , schema_editor ): MyModel = apps . get_model ( "myapp" , "MyModel" ) while MyModel . objects . filter ... ( uuid__isnull = True ) . exists (): with transaction . atomic (): for row in MyModel . objects . filter ( uuid__isnull = True )[: 1000 ]: row . uuid = uuid . uuid4 () row . sa ... 2026年10月08日