Ticket #17761: django-17761-tests.patch

File django-17761-tests.patch, 2.0 KB (added by agriffis, 4 years ago)
  • tests/regressiontests/model_inheritance_regress/tests.py

     
    77import datetime
    88from operator import attrgetter
    99
     10from django.db import IntegrityError
    1011from django.test import TestCase
    1112
    1213from .models import (Place, Restaurant, ItalianRestaurant, ParkingLot,
    1314    ParkingLot2, ParkingLot3, Supplier, Wholesaler, Child, SelfRefParent,
    1415    SelfRefChild, ArticleWithAuthor, M2MChild, QualityControl, DerivedM,
    1516    Person, BirthdayParty, BachelorParty, MessyBachelorParty,
    16     InternalCertificationAudit, BusStation, TrainStation)
     17    InternalCertificationAudit, BusStation, TrainStation, Vehicle, SportsCar)
    1718
    1819
    1920class ModelInheritanceTest(TestCase):
     
    408409        )
    409410        self.assertIs(BusStation._meta.pk.model, BusStation)
    410411        self.assertIs(TrainStation._meta.pk.model, TrainStation)
     412
     413    def test_explicit_parent_pk(self):
     414        # Regression test for #17761: save_base() does not properly detect
     415        # when parent primary key is uninitialized CharField
     416        boxster = SportsCar(pk='WP0CA2983XU622335', convertible=True)
     417        try:
     418            boxster.save()
     419        except IntegrityError:
     420            self.fail("IntegrityError should not have occurred.")
  • tests/regressiontests/model_inheritance_regress/models.py

     
    163163
    164164class TrainStation(Station):
    165165    zone = models.IntegerField()
     166
     167# Check that child can save with explicit parent pk, #17761
     168class Vehicle(models.Model):
     169    vin = models.CharField(max_length=17, primary_key=True)
     170
     171class SportsCar(Vehicle):
     172    convertible = models.BooleanField()
Back to Top