(self, func, robust=False)
| 725 | return self.SchemaEditorClass(self, *args, **kwargs) |
| 726 | |
| 727 | def on_commit(self, func, robust=False): |
| 728 | if not callable(func): |
| 729 | raise TypeError("on_commit()'s callback must be a callable.") |
| 730 | if self.in_atomic_block: |
| 731 | # Transaction in progress; save for execution on commit. |
| 732 | self.run_on_commit.append((set(self.savepoint_ids), func, robust)) |
| 733 | elif not self.get_autocommit(): |
| 734 | raise TransactionManagementError( |
| 735 | "on_commit() cannot be used in manual transaction management" |
| 736 | ) |
| 737 | else: |
| 738 | # No transaction in progress and in autocommit mode; execute |
| 739 | # immediately. |
| 740 | if robust: |
| 741 | try: |
| 742 | func() |
| 743 | except Exception as e: |
| 744 | name = getattr(func, "__qualname__", func) |
| 745 | logger.exception("Error calling %s in on_commit() (%s).", name, e) |
| 746 | else: |
| 747 | func() |
| 748 | |
| 749 | def run_and_clear_commit_hooks(self): |
| 750 | self.validate_no_atomic_block() |
no test coverage detected