cedadev / padocc

Other
2 stars 0 forks source link

TypeError: argument of type 'NoneType' is not iterable (scanning example water vapour .nc files) #34

Open efisher008 opened 4 months ago

efisher008 commented 4 months ago

This error was returned when running the command: python group_run.py scan ellie-test-wv

Traceback (most recent call last):
  File "/gws/nopw/j04/cedaproc/padocc/group_run.py", line 245, in <module>
    main(args)
  File "/gws/nopw/j04/cedaproc/padocc/group_run.py", line 184, in main
    allocations = assemble_allocations(args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/gws/nopw/j04/cedaproc/padocc/pipeline/allocate.py", line 59, in assemble_allocations
    if 'last_run' in detail:
       ^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

detail is set in /gws/nopw/j04/cedaproc/padocc/pipeline/allocate.py within the assemble_allocations() function:

proj_codes = get_codes(args.groupID, args.workdir, f'proj_codes/{args.repeat_id}')

    time_estms = {}
    time_defs_value = int(times[args.phase].split(':')[0])
    time_bands = {}

    for p in proj_codes:
        proj_dir       = get_proj_dir(p, args.workdir, args.groupID)
        detail         = get_proj_file(proj_dir, 'detail-cfg.json')

get_proj_file() is defined in the script utils.py:

def get_proj_file(proj_dir: str, proj_file: str) -> dict:
    """
    Returns the contents of a project file within a project code directory.

    :param proj_dir:    (str) The project code directory path.

    :param proj_file:   (str) Name of a file to access within the project directory.

    :returns: A dictionary of the contents of a json file or None if there are problems.
    """
    if not proj_file:
        projfile = proj_dir
    else:
        projfile = f'{proj_dir}/{proj_file}'
    if os.path.isfile(projfile):
        try:
            with open(projfile) as f:
                contents = json.load(f)
            return contents
        except:
            with open(projfile) as f:
                print(f.readlines())
            return None
    else:
        return None

It looks as though a None type object was possibly returned by get_prof_file() because there were issues with running the function. Is there supposed to be an existing file 'detail-cfg.json' for the proj_file argument in the working directory?

dwest77a commented 4 months ago

No the function is supposed to return a None value, but looking at it again now it makes more sense to return {} instead which is iterable but contains nothing. If you are able please change both return None to return {} in the cedaproc version and I will keep this issue in mind for when I get to update the main branch in the future.