Missing check for opts.fields != None (cannot iterate over if None)