python-youtube
python-youtube copied to clipboard
Bug: `RegionRestriction` model fields are not optional
Problem
Currently if the RegionRestriction object exists for a video, it is expected to have both fields (allowed, blocked).
https://github.com/sns-sdks/python-youtube/blob/7076d19633c8030373a615a7cd6e20b2ccd5c2d3/pyyoutube/models/video.py#L32-L33
But some video only have 1 set while the other is None,
resulting in this error:
{project_root}/.venv/lib/site-packages/dataclasses_json/core.py:184: RuntimeWarning: `NoneType` object value of non-optional type allowed detected when decoding RegionRestriction.
Solution
From my understanding both fields should be marked as optional, like this:
allowed: Optional[List[str]] = field(default=None)
blocked: Optional[List[str]] = field(default=None, repr=False)
The ideal way would probably be to somehow define that at least 1 of the 2 is needed and the other is optional. But I don't think that is possible.