mysociety / yournextrepresentative

A website for crowd-sourcing structured election candidate data
https://candidates.democracyclub.org.uk/
GNU Affero General Public License v3.0
56 stars 21 forks source link

Partial ISO birth date raises ValidationError #907

Open wfdd opened 8 years ago

wfdd commented 8 years ago
Internal Server Error: /election/vouleftikes-ekloges-2016/person/create/
Traceback (most recent call last):
  ...
django.core.exceptions.ValidationError: {'start_date': ['date seems not to be correct 1984-06-00']}

...

POST:{'birth_date': '1984-06',

candidates.models.popolo_extra.parse_approximate_date appends a '-00' to partial dates which popolo.behaviors.models.validate_partial_date can't parse.

wfdd commented 8 years ago

This appears to be attempting to insert the string representation of ApproximateDate into a CharField.

wfdd commented 8 years ago

I've patched it up with

class WorseApproximateDate(ApproximateDate):

    def __repr__(self):
        repr_, *_ = super().__repr__().partition('-00')
        return repr_

but then PersonExtra.dob_as_date can't parse it because

ValueError: day is out of range for month

and at this point I think I'm gonna need a drink ;)