Skip to content

Commit f197caf

Browse files
committed
Ensure text type on IP fields deserialization
1 parent e748c43 commit f197caf

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/marshmallow/fields.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,14 +1635,7 @@ def _deserialize(
16351635
if value is None:
16361636
return None
16371637
try:
1638-
if not isinstance(value, str):
1639-
# ip_address function is flexible in the terms of input value. In the case of
1640-
# marshalling, integer and binary address representation parsing may lead to
1641-
# confusion.
1642-
raise TypeError(
1643-
"Only dot-decimal and hexadecimal groups notations are supported."
1644-
)
1645-
return ipaddress.ip_address(value)
1638+
return ipaddress.ip_address(utils.ensure_text_type(value))
16461639
except (ValueError, TypeError) as error:
16471640
raise self.make_error("invalid_ip") from error
16481641

@@ -1658,9 +1651,7 @@ def _deserialize(
16581651
if value is None:
16591652
return None
16601653
try:
1661-
if not isinstance(value, str):
1662-
raise TypeError("Only dot-decimal notation is supported.")
1663-
return ipaddress.IPv4Address(value)
1654+
return ipaddress.IPv4Address(utils.ensure_text_type(value))
16641655
except (ValueError, TypeError) as error:
16651656
raise self.make_error("invalid_ip") from error
16661657

@@ -1676,9 +1667,7 @@ def _deserialize(
16761667
if value is None:
16771668
return None
16781669
try:
1679-
if not isinstance(value, str):
1680-
raise TypeError("Only hexadecimal groups notation is supported.")
1681-
return ipaddress.IPv6Address(value)
1670+
return ipaddress.IPv6Address(utils.ensure_text_type(value))
16821671
except (ValueError, TypeError) as error:
16831672
raise self.make_error("invalid_ip") from error
16841673

@@ -1767,7 +1756,7 @@ def __init__(
17671756
typing.Callable[[typing.Any], typing.Any],
17681757
typing.Callable[[typing.Any, typing.Dict], typing.Any],
17691758
] = None,
1770-
**kwargs
1759+
**kwargs,
17711760
):
17721761
# Set dump_only and load_only based on arguments
17731762
kwargs["dump_only"] = bool(serialize) and not bool(deserialize)

0 commit comments

Comments
 (0)