IPAddressField does not fully respect protocol='IPv6' #8712
Unanswered
Heinibal
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem Description
I am using the IPAddressField to validate ipv6 values and noticed that the error message for invalid values sometimes is 'Enter a valid IPv4 or IPv6 address.' instead of the more appropriate 'Enter a valid IPv6 address.'
The latter message appears if the invalid value doesn't contain the character ':'. The reason is that djangos
clean_ipv6_address
method is only called byIPAddressField.to_internal_value
if that character appears in the data:Suggested Solution
IPAddressField.__init__
already retrieves the appropriate error message for invalid values but does not actually use it. My suggestion would be to update the fieldserror_messages
:def __init__(self, protocol='both', **kwargs): self.protocol = protocol.lower() self.unpack_ipv4 = (self.protocol == 'both') super().__init__(**kwargs) validators, error_message = ip_address_validators(protocol, self.unpack_ipv4) + self.error_messages.update({'invalid': error_message}) self.validators.extend(validators)
I would be happy to work on this and create a pull request if this is determined to be a valid improvement. Of course I am also open to suggestions how to better fix this issue.
Beta Was this translation helpful? Give feedback.
All reactions