alan-turing-institute / AIrsenal

Machine learning Fantasy Premier League team
MIT License
296 stars 86 forks source link

Field names error in airsenal_dump_db #471

Open jack89roberts opened 2 years ago

jack89roberts commented 2 years ago

@jack89roberts while working on this, I came across an error that I'm not sure is known. On trying to dump the database, I get this error

  File "/Users/cmehta/opt/miniconda3/envs/airref/bin/airsenal_dump_db", line 8, in <module>
    sys.exit(main())
  File "/Users/cmehta/opt/miniconda3/envs/airref/lib/python3.8/site-packages/airsenal/scripts/dump_db_contents.py", line 25, in main
    save_table_fields(
  File "/Users/cmehta/opt/miniconda3/envs/airref/lib/python3.8/site-packages/airsenal/scripts/dump_db_contents.py", line 165, in save_table_fields
    write_rows_to_csv(csvfile, fields, dbclass)
  File "/Users/cmehta/opt/miniconda3/envs/airref/lib/python3.8/site-packages/airsenal/scripts/dump_db_contents.py", line 182, in write_rows_to_csv
    writer.writerow(row)
  File "/Users/cmehta/opt/miniconda3/envs/airref/lib/python3.8/csv.py", line 154, in writerow
    return self.writer.writerow(self._dict_to_list(rowdict))
  File "/Users/cmehta/opt/miniconda3/envs/airref/lib/python3.8/csv.py", line 149, in _dict_to_list
    raise ValueError("dict contains fields not in fieldnames: "
ValueError: dict contains fields not in fieldnames: 'fpl_api_id'

I suspect that this is because of this line https://github.com/alan-turing-institute/AIrsenal/blob/359ebbc2e52272fb1bedbd62a92c9e6fdb0b1981/airsenal/scripts/dump_db_contents.py#L24

Which says that only player_id, and name are to be written to csv whereas in the write function, https://github.com/alan-turing-institute/AIrsenal/blob/359ebbc2e52272fb1bedbd62a92c9e6fdb0b1981/airsenal/scripts/dump_db_contents.py#L171-L180

It iterates over all fields of the Player object which also has fpl_api_id. I was confused if it's known or not because the line setting player_fieldnames was committed a while ago and hasn't been updated. Is this a known issue that needs a fix?

Originally posted by @chahak13 in https://github.com/alan-turing-institute/AIrsenal/issues/382#issuecomment-1024830496

jack89roberts commented 2 years ago

Thanks @chahak13 , not something I've seen before but it doesn't particularly surprise me either. Haven't looked at it properly but I think most likely what's happened is the database fields have been updated/changed without the dump script being updated to reflect that.

chahak13 commented 2 years ago

@jack89roberts got it. I'll try to resolve it while doing #382 if it doesn't take a lot of effort, otherwise will work on it on a different PR later.

chahak13 commented 2 years ago

Okay, this was straightforward. I fixed it. I'll add the commit to the same PR as #382.