Ticket #10993: patch.diff

File patch.diff, 1.4 KB (added by szczav, 14 years ago)
  • django/db/models/query.py

     
    357357        Returns a tuple of (object, created), where created is a boolean
    358358        specifying whether an object was created.
    359359        """
     360        defaults = kwargs.pop('defaults', {})
    360361        assert kwargs, \
    361                 'get_or_create() must be passed at least one keyword argument'
    362         defaults = kwargs.pop('defaults', {})
     362                'get_or_create() must be passed at least one lookup argument'
    363363        try:
    364364            self._for_write = True
    365365            return self.get(**kwargs), False
  • tests/modeltests/get_or_create/tests.py

     
    5050            ManualPrimaryKeyTest.objects.get_or_create, id=1, data="Different"
    5151        )
    5252        self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original")
     53
     54        # If you pass default values without lookup arguments you will get an
     55        # error
     56        self.assertRaises(AssertionError, Person.objects.get_or_create,
     57            defaults={'first_name': "Tom",
     58                      'last_name': "Smith"})
Back to Top