Code

Opened 6 years ago

Closed 6 years ago

#6563 closed (duplicate)

field=None in get_or_create

Reported by: dcramer Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

There is a problem when using get_or_create in the following situation:

MyModel.objects.get_or_create(field=None, field1=Hi, defaults=dict(x=1, y=2))

One would expect this to insert field as None, if one doesnt match where field is NULL (how else would propose to approach that?)

The problem is it treats the insert as NULL, but not the select.

This goes along the same lines in Django where None != NULL, which I believe it should.

Attachments (0)

Change History (2)

comment:1 Changed 6 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

MyModel.objects.get_or_create(field__isnull=True, field1=Hi, defaults=dict(x=1, y=2))

comment:2 Changed 6 years ago by mtredinnick

  • Resolution set to duplicate
  • Status changed from new to closed
  • Summary changed from [bug] field=None in get_or_create to field=None in get_or_create

I'm going to mark this as a dupe of #2737, since it looks like just a consequence of the select behaviour, as you note. That behaviour's been changed in queyrset-refactor.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.