MCPcopy
hub / github.com/ponyorm/pony / flush

Method flush

pony/orm/core.py:1871–1907  ·  view source on GitHub ↗
(cache)

Source from the content-addressed store, hash-verified

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 = []

Callers

nothing calls this directly

Calls 9

throwFunction · 0.90
flush_disabledMethod · 0.80
_before_save_Method · 0.80
clearMethod · 0.80
_calc_modified_m2mMethod · 0.80
remove_m2mMethod · 0.80
_save_Method · 0.80
add_m2mMethod · 0.80
call_after_save_hooksMethod · 0.80

Tested by

no test coverage detected