'all_output_as_json=True ' in query object prevents access to its own methods
lchu122 opened this issue · 2 comments
I wanted to output as json the queries generated from the YahooFantasySportsQuery so I set the above parameter to True. I get the following error:
File "/Users/lukechu/Projects/TracyBowl/lib/python3.8/site-packages/yfpy/query.py", line 780, in get_league_key return self.get_game_metadata_by_game_id(self.game_id).game_key + ".l." + self.league_id AttributeError: 'str' object has no attribute 'game_key'
As an alternative I tried calling clean_data_dict() method on query output of a Player object, specifically on query.get_team_roster_player_stats_by_week(manager_id, week), and checked the types of both keys and values, and they were native Python types.
But I was unable to serialize the cleaned Player dict via json.dump() with the following error:
raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type Stat is not JSON serializable
Not sure how that object type was being picked up or how it remains for the cleaned Player dict.
Any ideas?
Also as an aside, not sure if it was done on purpose, but the output of 'player' in the Player Object is single quoted vs double quoted for what JSON expects.
@lchu122 thanks so much for the bug report. I've now released YFPY v9.0.0 which should fix the issues you are running into when trying to run some of the queries with JSON output.
Just as a clarification though, I've updated the all_output_as_json
parameter to be all_output_as_json_str
, as the purpose of that parameter is to output the data as a JSON string, not as Python JSON objects.
As for serialization, YFPY objects require the custom JSON serialization function in order to be serialized.
Lastly, in regards to your quoting comment, I wasn't able to recreate any issues with JSON quoting for the YFPY objects, but as far as I can tell now, all the integration tests pass both when all_output_as_json_str=True
and all_output_as_json_str=False
, and outputting all objects as JSON strings in code seems to work fine, so hopefully that isn't an issue for you anymore.