[Django] #16137: .get behaviour is inconsisten with .get_or_create

26 views
Skip to first unread message

Django

unread,
Jun 1, 2011, 9:43:42 AM6/1/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsisten with .get_or_create
---------------------------+----------------------------------------------
Reporter: wilfred@… | Owner: nobody
Type: Uncategorized | Status: new
Milestone: | Component: Database layer (models, ORM)
Version: 1.3 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
---------------------------+----------------------------------------------
It's really useful to be able to do

{{{ MyModel.objects.get() }}}

when you've got a singleton model. Sadly, .get_or_create doesn't allow you
to call it in the same way:

{{{ MyModel.objects.get_or_create() }}}

This throws an AssertionError "get_or_create() must be passed at least one
keyword argument". Could this requirement be dropped?

--
Ticket URL: <https://code.djangoproject.com/ticket/16137>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 1, 2011, 4:56:01 PM6/1/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsisten with .get_or_create
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody
Type: | Status: new
Uncategorized | Component: Database layer
Milestone: | (models, ORM)
Version: 1.3 | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

The check is enforced at the very beginning of
`django.db.models.query.get_or_create()`:

{{{
assert kwargs, 'get_or_create() must be passed at least one
keyword argument'
}}}

This line has been there, unchanged, since the merge of queryset-refactor.
Actually, it was even in the initial proposal by Adrian:
https://groups.google.com/group/django-developers/msg/1c39b286a3e9e2cb

As far as I can tell, it is not necessary.

--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:1>

Django

unread,
Jun 1, 2011, 4:56:13 PM6/1/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsisten with .get_or_create
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Component: Database layer
Milestone: | (models, ORM)
Version: 1.3 | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 1
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* type: Uncategorized => Cleanup/optimization
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:2>

Django

unread,
Jun 10, 2011, 12:02:45 AM6/10/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Component: Database layer
Milestone: | (models, ORM)
Version: 1.3 | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 1
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by melinath):

* ui_ux: => 0


Comment:

Removing that line causes no unexpected test failures.

--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:3>

Django

unread,
Sep 9, 2011, 10:07:26 PM9/9/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Component: Database layer
Milestone: | (models, ORM)
Version: 1.3 | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 1
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by tobias):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:4>

Django

unread,
Oct 31, 2011, 3:12:38 PM10/31/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 1
Keywords: | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: 0 => 1
* needs_docs: 0 => 1


Comment:

Patch doesn't apply cleanly.

Also, this needs a mention in the release notes -- nothing fancy, but
people could be relying on the current behavior, even if it isn't really
justified.

--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:5>

Django

unread,
Nov 13, 2011, 11:59:47 AM11/13/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: poirier
Type: | Status: assigned
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 1
Keywords: | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by poirier):

* owner: nobody => poirier
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:6>

Django

unread,
Nov 13, 2011, 12:13:38 PM11/13/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: poirier
Type: | Status: assigned
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by poirier):

* needs_docs: 1 => 0
* needs_tests: 1 => 0
* needs_better_patch: 1 => 0


Comment:

Updated patch to apply to Django trunk.
Added brief note to 1.4 release notes.

--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:7>

Django

unread,
Nov 13, 2011, 3:14:25 PM11/13/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: poirier
Type: | Status: assigned
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by charettes):

Updated patch with a more descriptive test failure (instead of
{{{self.assertTrue(False)}}})

--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:8>

Django

unread,
Nov 18, 2011, 10:32:28 AM11/18/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by poirier):

* owner: poirier => nobody
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:9>

Django

unread,
Nov 22, 2011, 2:16:23 AM11/22/11
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by aaugustin):

#10993 was closed in favor of this ticket.

--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:10>

Django

unread,
May 24, 2013, 4:46:14 PM5/24/13
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* cc: timograham@… (added)


Comment:

Updated patch to apply cleanly to master.
https://github.com/django/django/pull/1214

--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:11>

Django

unread,
May 25, 2013, 4:10:38 AM5/25/13
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Ready for
Severity: Normal | checkin
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by claudep):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:12>

Django

unread,
May 26, 2013, 10:36:55 AM5/26/13
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Ready for
Severity: Normal | checkin
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by aaugustin):

I left two minor comments on the PR, otherwise this is indeed RFC.

--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:13>

Django

unread,
May 27, 2013, 1:52:09 PM5/27/13
to django-...@googlegroups.com
#16137: .get behaviour is inconsistent with .get_or_create when no kwargs are given
-------------------------------------+-------------------------------------
Reporter: wilfred@… | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: 1.3
Component: Database layer | Resolution: fixed

(models, ORM) | Triage Stage: Ready for
Severity: Normal | checkin
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* status: new => closed
* resolution: => fixed


Comment:

In 90af278203963e3e3f96e443971cd38a2dad34e4:

Fixed #16137 - Removed kwargs requirement for QuerySet.get_or_create

Thanks wilfred@, poirier, and charettes for work
on the patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/16137#comment:14>

Reply all
Reply to author
Forward
0 new messages