rapidpro / rapidpro-python

Python client library for the RapidPro API
BSD 3-Clause "New" or "Revised" License
18 stars 27 forks source link

Null DatetimeField raises an exception upon serialisation request #37

Closed system7ltd closed 8 years ago

system7ltd commented 8 years ago

Objects with DatetimeField attributes cannot be properly serialised when any of their DatetimeField attributes is not set (i.e. set to null in the JSON response). This makes the following scenario possible:

  1. fetch data from the server (e.g. TembaClient(...).get_runs()) - the data is internally deserialised by rapidpro-python
  2. fed the result of this deserialisation process back to rapidpro-python to have it (re)serialised
  3. error (please see the example traceback below)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ego/.virtualenvs/rapidpro-python/local/lib/python2.7/site-packages/temba_client/serialization.py", line 63, in serialize
    field_value = field.serialize(attr_value)
  File "/home/ego/.virtualenvs/rapidpro-python/local/lib/python2.7/site-packages/temba_client/serialization.py", line 148, in serialize
    return [self.item_class.serialize(item) for item in value]
  File "/home/ego/.virtualenvs/rapidpro-python/local/lib/python2.7/site-packages/temba_client/serialization.py", line 63, in serialize
    field_value = field.serialize(attr_value)
  File "/home/ego/.virtualenvs/rapidpro-python/local/lib/python2.7/site-packages/temba_client/serialization.py", line 122, in serialize
    return format_iso8601(value)
  File "/home/ego/.virtualenvs/rapidpro-python/local/lib/python2.7/site-packages/temba_client/utils.py", line 40, in format_iso8601
    return six.text_type(value.astimezone(pytz.UTC).strftime(_format))
AttributeError: 'NoneType' object has no attribute 'astimezone'
rowanseymour commented 8 years ago

PR looks fine besides small tweak. Am wondering what you are using serialization for?