File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed
Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -27,13 +27,16 @@ def get_migration_ids_to_remove(self) -> t.List[str]:
2727 migration_module_dict = migration_module_dict
2828 )
2929
30- migration_ids_to_remove = (
30+ query = (
3131 Migration .select (Migration .name )
3232 .where (Migration .app_name == self .app_name )
33- .where (Migration .name .not_in (migration_ids ))
3433 .output (as_list = True )
35- .run_sync ()
3634 )
35+
36+ if len (migration_ids ) > 0 :
37+ query = query .where (Migration .name .not_in (migration_ids ))
38+
39+ migration_ids_to_remove = query .run_sync ()
3740 return migration_ids_to_remove
3841
3942 def run (self ):
Original file line number Diff line number Diff line change 2424)
2525from piccolo .columns .combination import Where
2626from piccolo .columns .defaults .base import Default
27- from piccolo .custom_types import Iterable
2827from piccolo .querystring import QueryString
2928from piccolo .utils .warnings import colored_warning
3029
@@ -257,10 +256,18 @@ def _validate_default(
257256 f"{ allowed_types } "
258257 )
259258
260- def is_in (self , values : Iterable ) -> Where :
259+ def is_in (self , values : t .List [t .Any ]) -> Where :
260+ if len (values ) == 0 :
261+ raise ValueError (
262+ "The `values` list argument must contain at least one value."
263+ )
261264 return Where (column = self , values = values , operator = In )
262265
263- def not_in (self , values : Iterable ) -> Where :
266+ def not_in (self , values : t .List [t .Any ]) -> Where :
267+ if len (values ) == 0 :
268+ raise ValueError (
269+ "The `values` list argument must contain at least one value."
270+ )
264271 return Where (column = self , values = values , operator = NotIn )
265272
266273 def like (self , value : str ) -> Where :
Original file line number Diff line number Diff line change @@ -24,7 +24,13 @@ def test_is_in(self):
2424 sql = _where .__str__ ()
2525 self .assertEqual (sql , "band.name IN ('Pythonistas', 'Rustaceans')" )
2626
27+ with self .assertRaises (ValueError ):
28+ Band .name .is_in ([])
29+
2730 def test_not_in (self ):
2831 _where = Band .name .not_in (["CSharps" ])
2932 sql = _where .__str__ ()
3033 self .assertEqual (sql , "band.name NOT IN ('CSharps')" )
34+
35+ with self .assertRaises (ValueError ):
36+ Band .name .not_in ([])
You can’t perform that action at this time.
0 commit comments