Ticket #16137: 16137.2.diff

File 16137.2.diff, 2.6 KB (added by Simon Charette, 13 years ago)

With a more descriptive test failure

  • django/db/models/query.py

    diff --git a/django/db/models/query.py b/django/db/models/query.py
    index be42d02..48e911b 100644
    a b class QuerySet(object):  
    414414        Returns a tuple of (object, created), where created is a boolean
    415415        specifying whether an object was created.
    416416        """
    417         assert kwargs, \
    418                 'get_or_create() must be passed at least one keyword argument'
    419417        defaults = kwargs.pop('defaults', {})
    420418        lookup = kwargs.copy()
    421419        for f in self.model._meta.fields:
  • docs/releases/1.4.txt

    diff --git a/docs/releases/1.4.txt b/docs/releases/1.4.txt
    index 49284fb..b2a8889 100644
    a b Django 1.4 also includes several smaller improvements worth noting:  
    480480* Added the :djadminopt:`--no-location` option to the :djadmin:`makemessages`
    481481  command.
    482482
     483* The :meth:`~django.db.models.query.QuerySet.get_or_create` method no longer
     484  requires at least one keyword argument.
     485
    483486.. _backwards-incompatible-changes-1.4:
    484487
    485488Backwards incompatible changes in 1.4
  • tests/modeltests/get_or_create/models.py

    diff --git a/tests/modeltests/get_or_create/models.py b/tests/modeltests/get_or_create/models.py
    index 1de5a6e..d97c6c2 100644
    a b class Person(models.Model):  
    1717    def __unicode__(self):
    1818        return u'%s %s' % (self.first_name, self.last_name)
    1919
     20
     21class DefaultPerson(models.Model):
     22    first_name = models.CharField(max_length=100, default="Anonymous")
     23
     24
    2025class ManualPrimaryKeyTest(models.Model):
    2126    id = models.IntegerField(primary_key=True)
    2227    data = models.CharField(max_length=100)
  • tests/modeltests/get_or_create/tests.py

    diff --git a/tests/modeltests/get_or_create/tests.py b/tests/modeltests/get_or_create/tests.py
    index 4cf4450..47c7fef 100644
    a b from datetime import date  
    55from django.db import IntegrityError
    66from django.test import TestCase
    77
    8 from .models import Person, ManualPrimaryKeyTest
     8from .models import Person, DefaultPerson, ManualPrimaryKeyTest
    99
    1010
    1111class GetOrCreateTests(TestCase):
    class GetOrCreateTests(TestCase):  
    5252            ManualPrimaryKeyTest.objects.get_or_create, id=1, data="Different"
    5353        )
    5454        self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original")
     55
     56    def test_get_or_create_empty(self):
     57        try:
     58            DefaultPerson.objects.get_or_create()
     59        except AssertionError:
     60            self.fail("If all the attributes on a model have defaults, we "
     61                      "shouldn't need to pass any arguments.")
Back to Top