(cache)
| 1869 | try: yield |
| 1870 | finally: cache.noflush_counter -= 1 |
| 1871 | def flush(cache): |
| 1872 | if cache.noflush_counter: return |
| 1873 | assert cache.is_alive |
| 1874 | assert not cache.saved_objects |
| 1875 | prev_immediate = cache.immediate |
| 1876 | cache.immediate = True |
| 1877 | try: |
| 1878 | for i in range(50): |
| 1879 | if not cache.modified: return |
| 1880 | |
| 1881 | with cache.flush_disabled(): |
| 1882 | for obj in cache.objects_to_save: # can grow during iteration |
| 1883 | if obj is not None: obj._before_save_() |
| 1884 | |
| 1885 | cache.query_results.clear() |
| 1886 | modified_m2m = cache._calc_modified_m2m() |
| 1887 | for attr, (added, removed) in modified_m2m.items(): |
| 1888 | if not removed: continue |
| 1889 | attr.remove_m2m(removed) |
| 1890 | for obj in cache.objects_to_save: |
| 1891 | if obj is not None: obj._save_() |
| 1892 | for attr, (added, removed) in modified_m2m.items(): |
| 1893 | if not added: continue |
| 1894 | attr.add_m2m(added) |
| 1895 | |
| 1896 | cache.max_id_cache.clear() |
| 1897 | cache.modified_collections.clear() |
| 1898 | cache.objects_to_save[:] = () |
| 1899 | cache.modified = False |
| 1900 | |
| 1901 | cache.call_after_save_hooks() |
| 1902 | else: |
| 1903 | if cache.modified: throw(TransactionError, |
| 1904 | 'Recursion depth limit reached in obj._after_save_() call') |
| 1905 | finally: |
| 1906 | if not cache.in_transaction: |
| 1907 | cache.immediate = prev_immediate |
| 1908 | def call_after_save_hooks(cache): |
| 1909 | saved_objects = cache.saved_objects |
| 1910 | cache.saved_objects = [] |
nothing calls this directly
no test coverage detected