The code tries to write the short format when some values as None, but when writing the long format it would write any None value as is which is invalid, use 0 for None values instead.
The code tries to write the short format when some values as None, but when writing the long format it would write any None value as is which is invalid, use 0 for None values instead.