Skip to content

Duplicated GenericIPAddressField validation errors with ModelSerializer and protocol #9645

Closed

Description

@HansAarneLiblik

Hi!

I'm using GenericIPAddressField with explicit protocol as IPv4 (Also reproduces with IPv6) and ModelSerializer. If the input is not an valid IpAddress, DRF generates duplicate(ish) errors.

Repro

from django.db import models
from rest_framework.serializers import ModelSerializer


class A(models.Model):
    address = models.GenericIPAddressField(protocol="IPv4")  # Also reproduces with `IPv6`

    class Meta:
        app_label = "main"

class ASerializer(ModelSerializer[A]):
    class Meta:
        model = A
        fields = "__all__"


ser = ASerializer(data={'address': 'not an ip address'})
ser.is_valid(raise_exception=True)

Result

rest_framework.exceptions.ValidationError: {'address': [
    ErrorDetail(string='Enter a valid IPv4 address.', code='invalid'), 
    ErrorDetail(string='Enter a valid IPv4 or IPv6 address.', code='invalid')
]}

The second error message is incorrect

Thanks!

Activity

  1. Daksh2000 commented on Feb 9, 2025

    @Daksh2000

    Hi @HansAarneLiblik , Can I take this issue ?

  2. HansAarneLiblik commented on Feb 9, 2025

    @HansAarneLiblik
    Author

    Sure, I don't mind!

  3. Daksh2000 commented on Feb 9, 2025

    @Daksh2000

    Hi @HansAarneLiblik ,
    I have raised a PR , #9647
    Please share your views on it.

  4. NikeGunn commented on Apr 26, 2025

    @NikeGunn
  5. stale commented on Jul 19, 2025

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  6. added a commit that references this issue on Aug 12, 2026
    1f599b1
  7. added a commit that references this issue on Oct 8, 2026
    cd712a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions