mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 17:26:10 -06:00
#12278 to_internal_value is called before validation! need to raise validation error if incorrect format
This commit is contained in:
parent
95e37e47cc
commit
38f1b91988
@ -6,7 +6,7 @@ from ipam import models
|
|||||||
from ipam.models.l2vpn import L2VPNTermination, L2VPN
|
from ipam.models.l2vpn import L2VPNTermination, L2VPN
|
||||||
from ipam.validators import validate_ipaddress_with_mask
|
from ipam.validators import validate_ipaddress_with_mask
|
||||||
from netbox.api.serializers import WritableNestedSerializer
|
from netbox.api.serializers import WritableNestedSerializer
|
||||||
from netaddr import IPNetwork
|
from netaddr import AddrFormatError, IPNetwork
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'IPAddressField',
|
'IPAddressField',
|
||||||
@ -48,7 +48,12 @@ class IPAddressField(serializers.CharField):
|
|||||||
self.validators.append(validator)
|
self.validators.append(validator)
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
return IPNetwork(data)
|
try:
|
||||||
|
IPNetwork(data)
|
||||||
|
except AddrFormatError:
|
||||||
|
raise serializers.ValidationError("Invalid IP address format: {}".format(data))
|
||||||
|
except (TypeError, ValueError) as e:
|
||||||
|
raise serializers.ValidationError(e)
|
||||||
|
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
return str(value)
|
return str(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user