﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24708	forms.GenericIPAddressField.to_python behaves differently to other CharField subclasses.	Keryn Knight	Pradeek	"Other `forms.fields.CharField` subclasses (`UUIDField`, `URLField`), when they replace the `to_python` method, call `super(..., self).to_python(...)` before acting on the value.

`GenericIPAddressField` however, [https://github.com/django/django/blob/master/django/forms/fields.py#L1220 does not], which means it calls `.strip()` on the input, assuming the input is a string.

Thus, the following fails:
{{{
>>> GenericIPAddressField().to_python(1)
AttributeError: 'int' object has no attribute 'strip'
}}}
where the other aforementioned subclasses succeed in their functionality:
{{{
>>> URLField().to_python(1)
'http://1'
>>> UUIDField().to_python(1)
ValidationError: ['Enter a valid UUID.']
}}}
Because the call to `super(...)` ensures either `''` or `smart_text(...)` is returned.

I ''think'' the fix is thus:
{{{
    def to_python(self, value):
        value = super(GenericIPAddressField, self).to_python(value).strip()  # this is the fix line.
        if value in self.empty_values:
            return ''
        if value and ':' in value:
            return clean_ipv6_address(value, self.unpack_ipv4)
        return value
}}}"	Bug	closed	Forms	dev	Normal	fixed		django@…	Ready for checkin	1	0	0	0	1	0
