autocommit()
, commit_on_success()
and commit_manually()
functions familiar to working with transactions from the django.db.transaction
module django.db.transaction
now considered obsolete and will remain up to 1.8 compatible. atomic()
comes to replace them.COMMIT;
SQL query is sent independently). This mechanism worked quite well in the case of independent transactions, but in the case of nested use of obsolete functions, the result could be incorrect. For example, if we have two commit_on_success()
blocks nested inside one another, then a situation may arise that the result of executing the internal block will be commited, having broken, from the transaction point of view, the atomicity of the external block.atomic()
, which is not afraid of nesting, since in the case of an external block, it works with a transaction, and in the case of a nested block, it works with SQL save points . Also, instead of TransactionMiddleware
, the configuration constant ATOMIC_REQUESTS
, when setting its value to True
(the default value is False
), the django will try to process one HTTP request in one transaction. Those. request executed without any problems - commited, no - rolled back.atomic()
can be used as a decorator as well as a context manager: from django.db import transaction # @transaction.atomic def viewfunc1(request): # do_stuff() and as a context manager: # def viewfunc2(request): # do_stuff() with transaction.atomic(): # do_more_stuff()
CONN_MAX_AGE
.django.test.runner.DiscoverRunner
, which uses the logic of finding modules with tests from unittest2
. Now tests can be located in any modules, if the name of the file containing them matches the test*.py
mask.models.py
and tests/__init__.py
are found, and accordingly, they will not be run (unlike the behavior in previous versions). The easiest solution is to rename them to something like test_models.py
and tests/test.py
And also, doctoral tests will no longer be loaded automatically. But they will not be difficult to turn back, following the instructions in the unittest
documentation../manage.py test
now has the option --pattern
, indicating that, as it is not difficult to guess, you can change the mask to search for files with tests.django-admin.py check
command now allows you to check the compatibility of a project or application with the current version of the jungle, issuing alerts in case of incompatible locations. It is assumed that this command will assist in the transition to new versions of the framework.QuerySet
supports syntactic sugar, in the form of the first()
and last()
methods, and earliest()
in addition to the latest()
method.hour
, minute
and second
in addition to the previously added year
, month
and day
when searching for fields with a date and / or time.Source: https://habr.com/ru/post/201168/
All Articles