Opened 8 years ago

Closed 8 years ago

#26884 closed Bug (fixed)

update_or_create does not evaluate callables in defaults for update case

Reported by: Jensen Cochran Owned by: Kenneth
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: update_or_create
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Ticket #26638 added support for accepting callables in the 'defaults' parameter of get_or_create and update_or_create. In the case where update_or_create is updating, the callables are not evaluated. I have written a test for update_or_create that demonstrates this behavior (attached).

Here is the traceback for that test failure:

======================================================================
FAIL: test_update_callable_default (get_or_create.tests.UpdateOrCreateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python2.7/unittest/case.py", line 369, in run
    testMethod()
  File "/home/default/sandbox/django/tests/get_or_create/tests.py", line 423, in test_update_callable_default
    self.assertEqual(obj.last_name, 'NotHarrison')
  File "/usr/lib64/python2.7/unittest/case.py", line 553, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib64/python2.7/unittest/case.py", line 546, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: <function <lambda> at 0x22d0320> != u'NotHarrison'

----------------------------------------------------------------------

Attachments (1)

26884.diff (1.0 KB ) - added by Jensen Cochran 8 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Jensen Cochran, 8 years ago

Type: UncategorizedBug

by Jensen Cochran, 8 years ago

Attachment: 26884.diff added

comment:2 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Kenneth, 8 years ago

Has patch: set
Owner: changed from nobody to Kenneth
Status: newassigned

comment:4 by Tim Graham, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 841cb45:

Fixed #26884 -- Evaluated callables in QuerySet.update_or_create()'s defaults when updating.

Note: See TracTickets for help on using tickets.
Back to Top