Es macht nicht viel Sinn, einen faulen sparen zu haben, oder? Djangos QuerySets
sind faul, die save
Methode des Modells ist nicht.
Von der django Quelle:
django/db/models/base.py
, Linien 424-437:
def save(self, force_insert=False, force_update=False, using=None):
"""
Saves the current instance. Override this in a subclass if you want to
control the saving process.
The 'force_insert' and 'force_update' parameters can be used to insist
that the "save" must be an SQL insert or update (or equivalent for
non-SQL backends), respectively. Normally, they should not be set.
"""
if force_insert and force_update:
raise ValueError("Cannot force both insert and updating in \
model saving.")
self.save_base(using=using, force_insert=force_insert,
force_update=force_update)
save.alters_data = True
Dann tut save_base
das Heben schwerer Lasten (gleiche Datei, Zeilen 439-545):
...
transaction.commit_unless_managed(using=using)
...
Und in django/db/transaction.py
, Zeilen 167-178 finden Sie:
def commit_unless_managed(using=None):
"""
Commits changes if the system is not in managed transaction mode.
"""
...
P.S. Alle Zeilennummern gelten für die Django-Version (1, 3, 0, 'alpha', 0)
.
Eigentlich wären in einigen Fällen faule Sparer vorzuziehen. Lazy Saves würde viel kürzere Transaktionen ermöglichen, ohne dass der Programmierer etwas unternehmen muss. Siehe http://stackoverflow.com/questions/3215833/django-keeping-save-based-transactions-short – Jonathan
Einverstanden, gute Antwort, aber ja, manchmal macht es viel Sinn, eine faule sparen zu haben. – Seth