File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -760,11 +760,21 @@ def exists(cls: Type[_T]) -> bool:
760760 return False
761761
762762 @classmethod
763- def delete_table (cls ) -> Any :
763+ def delete_table (cls , wait : bool = False ) -> Any :
764764 """
765765 Delete the table for this model
766+
767+ :param wait: If set, then this call will block until the table is deleted
766768 """
767- return cls ._get_connection ().delete_table ()
769+ result = cls ._get_connection ().delete_table ()
770+ if not wait :
771+ return result
772+
773+ while True :
774+ if not cls .exists ():
775+ return result
776+
777+ time .sleep (2 )
768778
769779 @classmethod
770780 def describe_table (cls ) -> Any :
Original file line number Diff line number Diff line change @@ -3438,3 +3438,18 @@ def test_delete(add_version_condition: bool) -> None:
34383438 }
34393439 args = req .call_args [0 ][1 ]
34403440 assert args == expected
3441+
3442+ @patch .object (target = Model , attribute = "exists" , autospec = True )
3443+ @patch .object (target = Model , attribute = "_get_connection" , autospec = True )
3444+ def test_delete_with_wait (mock__get_connection , mock_exists ):
3445+ """Test that the wait argument works as expected on the delete."""
3446+ # Make the first two exists calls show the table as still existing, then have the
3447+ # last call show it has been deleted.
3448+ mock_exists .side_effect = (True , True , False )
3449+
3450+ result = Model .delete_table ()
3451+
3452+ # Should have returned the delete value.
3453+ assert result == mock__get_connection .return_value .delete_table .return_value
3454+ # Should have called exists 3 times.
3455+ assert mock_exists .call_count == 3
You can’t perform that action at this time.
0 commit comments