Serializer Does Not Call Validator

My serializer based off of ModelSerializer does not call my validate function regardless of whether I define validators = [my_validator] where my_validator is a function defined external to the serializer or I def validator(self, attrs) inside the serializer class but outside of class Meta.

My model is something like:

def validate_coordinate(value):
    print("Hello from validate_coordinate")
    #breakpoint()
    if value < -180 or value > 180:
        raise ValidationError(f"{value} outside range of -180 to 180 degrees")

class SpacexAsset(models.Model):

    # Orbit is implemented the "long way" with a class and tuples
    # to force the human-readable form to not be title-cased.
    class SatelliteOrbitChoices(models.TextChoices):
        LEO = "LEO", "LEO"
        GEO = "GEO", "GEO"
        NoOrbit = "", ""

    AssetTypeChoices = models.TextChoices("AssetType",
                                          "Satellite GroundStation")

    asset_type = models.CharField(choices=AssetTypeChoices.choices,
                                  max_length=16)

    latitude = models.FloatField(validators=[validate_coordinate])
    longitude = models.FloatField(validators=[validate_coordinate])

    # This field is required only if the asset type is "Satellite"
    orbit = models.CharField(choices=SatelliteOrbitChoices.choices,
                             max_length=8, blank=True)

    def __str__(self):
        """A string representation of the asset record name."""
        return self.name

My View is:

class SpacexViewSet(viewsets.ModelViewSet):
    queryset = SpacexAsset.objects.all()
    serializer_class = SpacexAssetSerializer

An abridged version of my serializer is:

def validate2(self, attrs):
    print("Hi there from validate2")
    breakpoint()
    return attrs

class SpacexAssetSerializer(serializers.ModelSerializer):
    def validate(self, attrs):
        print("Hi there from validate")
        breakpoint()
        return attrs

    class Meta:
        model = SpacexAsset
        fields = ['asset-type',
                  'latitude', 'longitude', 'orbit']
        extra_kwargs = {
            'asset-type': {'source': 'asset_type'},
        }

        validators = [validate2]

What I expect is that my validator to be called when I use the built-in admin interface to change an asset field value. What I am seeing is nothing.

That is, my validator, whether a declared validator function within my serializer class or a function in the Meta validators list, is not called. No debugging prints are seen, no breakpoints are taken. The print statements in the field validator are seen, so we know that validation does happen at the model level.

I’ve gone so far as to put print/breakpoint statements in the django rest code serializer.py in is_valid(), get_validators(), run_validation, and to_internal_value(), but I don’t see anything, so I’m guessing they are not called, but why?

I’ve re-read the documentation, but there isn’t anything about special cases.

I’ve looked at some previous Stack Overflow postings, but most of the them involved either earlier (built-in) field validation errors causing user-added validation functions like this to be skipped, but again that is not the case here. No errors are reported at all and no messages appear in the window where “manage.py runserver” is running.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật