IMAP-Science-Operations-Center / imap-data-access

Package to download, query, and upload files from the IMAP Science Data Center.
MIT License
0 stars 7 forks source link

BUG - query API fails with None error #26

Closed tech3371 closed 3 months ago

tech3371 commented 3 months ago

Description of the issue

Query fails with None error

Steps to reproduce the issue

    1. 3.

Run this command

imap-data-access query --instrument 'mag'

Code Snippet:

Code
def _print_query_results_table(query_results: list[dict]):
    """Print the query results in a table.

    Parameters
    ----------
    query_results : list
        A list of dictionaries containing the query results
    """
    num_files = len(query_results)
    print(f"Found [{num_files}] matching files")
    if num_files == 0:
        return
    format_string = "{:<10}|{:<10}|{:<10}|{:<10}|{:<10}|{:<7}|{:<50}|"
    # Add hyphens for a separator between header and data
    hyphens = "-" * 111 + "|"
    print(hyphens)
    header = [
        "Instrument",
        "Data Level",
        "Descriptor",
        "Start Date",
        "Repointing",
        "Version",
        "Filename",
    ]
    print(format_string.format(*header))
    print(hyphens)

    # Print data
    for item in query_results:
        values = [
            item["instrument"],
            item["data_level"],
            item["descriptor"],
            item["start_date"],
            item["repointing"],
            item["version"],
            os.path.basename(item["file_path"]),
        ]
        print(format_string.format(*values))
    # Close the table
    print(hyphens)

Expected behavior (What should happen)

imap-data-access query --instrument 'mag' Found [1] matching files table output

Actual behavior (What does happen)

sds-data-manager-py3.10) tech3371@MacL4670 sds-data-manager % imap-data-access query --instrument 'mag'
Found [1] matching files ---------------------------------------------------------------------------------------------------------------
Instrument Data Level Descriptor Start Date Repointing Version Filename

Traceback (most recent call last): File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/bin/imap-data-access", line 8, in sys.exit(main()) File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/imap_data_access/cli.py", line 295, in main args.func(args) File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/imap_data_access/cli.py", line 117, in _query_parser _print_query_results_table(query_results) File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/imap_data_access/cli.py", line 82, in _print_query_results_table print(format_string.format(*values)) TypeError: unsupported format string passed to NoneType.format

Additional notes

No response

Affected areas (code, data, or process)

cli.py and code line 79

Suggested fix?

def _print_query_results_table(query_results: list[dict]): """Print the query results in a table.

Parameters
----------
query_results : list
    A list of dictionaries containing the query results
"""
num_files = len(query_results)
print(f"Found [{num_files}] matching files")
if num_files == 0:
    return
format_string = "{:<10}|{:<10}|{:<10}|{:<10}|{:<10}|{:<7}|{:<50}|"
# Add hyphens for a separator between header and data
hyphens = "-" * 111 + "|"
print(hyphens)
header = [
    "Instrument",
    "Data Level",
    "Descriptor",
    "Start Date",
    "Repointing",
    "Version",
    "Filename",
]
print(format_string.format(*header))
print(hyphens)

# Print data
for item in query_results:
    values = [
        item["instrument"],
        item["data_level"],
        item["descriptor"],
        item["start_date"],
        item["repointing"],
        item["version"],
        os.path.basename(item["file_path"]),
    ]
    # Convert None to an empty string (or another default value)
    values = [v if v is not None else '' for v in values]
    print(format_string.format(*values))
# Close the table
print(hyphens)