@@ -124,6 +124,7 @@ def __init__(self):
124124 self ._default_logging_level = self ._logger .level
125125 self ._record_writer = None
126126 self ._records = None
127+ self ._allow_empty_list = False
127128
128129 def __str__ (self ):
129130 text = ' ' .join (chain ((type (self ).name , str (self .options )), [] if self .fieldnames is None else self .fieldnames ))
@@ -413,7 +414,7 @@ def prepare(self):
413414 """
414415 pass
415416
416- def process (self , argv = sys .argv , ifile = sys .stdin , ofile = sys .stdout ):
417+ def process (self , argv = sys .argv , ifile = sys .stdin , ofile = sys .stdout , allow_empty_list = False ):
417418 """ Process data.
418419
419420 :param argv: Command line arguments.
@@ -425,10 +426,16 @@ def process(self, argv=sys.argv, ifile=sys.stdin, ofile=sys.stdout):
425426 :param ofile: Output data file.
426427 :type ofile: file
427428
429+ :param allow_empty_list: Allow empty results
430+ :type allow_empty_list: bool
431+
428432 :return: :const:`None`
429433 :rtype: NoneType
430434
431435 """
436+
437+ self ._allow_empty_list = allow_empty_list
438+
432439 if len (argv ) > 1 :
433440 self ._process_protocol_v1 (argv , ifile , ofile )
434441 else :
@@ -965,8 +972,10 @@ def _execute_v2(self, ifile, process):
965972 def _execute_chunk_v2 (self , process , chunk ):
966973 metadata , body = chunk
967974
968- if len (body ) <= 0 :
969- return
975+ if len (body ) <= 0 and not self ._allow_empty_list :
976+ raise ValueError (
977+ "No records found to process. Set _allow_empty_list=True in dispatch function to move forward "
978+ "with empty records." )
970979
971980 records = self ._read_csv_records (StringIO (body ))
972981 self ._record_writer .write_records (process (records ))
@@ -1063,8 +1072,7 @@ def iteritems(self):
10631072SearchMetric = namedtuple ('SearchMetric' , ('elapsed_seconds' , 'invocation_count' , 'input_count' , 'output_count' ))
10641073
10651074
1066-
1067- def dispatch (command_class , argv = sys .argv , input_file = sys .stdin , output_file = sys .stdout , module_name = None ):
1075+ def dispatch (command_class , argv = sys .argv , input_file = sys .stdin , output_file = sys .stdout , module_name = None , allow_empty_list = False ):
10681076 """ Instantiates and executes a search command class
10691077
10701078 This function implements a `conditional script stanza <https://docs.python.org/2/library/__main__.html>`_ based on the value of
@@ -1124,4 +1132,4 @@ def stream(records):
11241132 assert issubclass (command_class , SearchCommand )
11251133
11261134 if module_name is None or module_name == '__main__' :
1127- command_class ().process (argv , input_file , output_file )
1135+ command_class ().process (argv , input_file , output_file , allow_empty_list )
0 commit comments