﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32898	get_or_create() with filter() has surprising behaviour	Jamie Cockburn	nobody	"This documentation:
https://docs.djangoproject.com/en/3.2/ref/models/querysets/#get-or-create

That doc says you can combine `filter()` with `get_or_create()`. Great!

But the resulting behaviour is somewhat surprising.

Given the following model:
{{{#!python
class A(models.Model):
    a = models.CharField()
    b = models.CharField()
}}}

I would expect that the following two lines would be fuctionally equivalent:
{{{#!python
A.objects.get_or_create(a=""something"", b=""another"")
A.objects.filter(a=""something"").get_or_create(b=""another"")
}}}

If an instance `{""a"": ""something"", ""b"": ""another""}` already exists in the database then they ''are'' equivalent.

If the instance does not exist, the `filter().get_or_create()` version will create an instance `{""a"": """", ""b"": ""another""}`, throwing away the kwargs passed to `filter()`.

By example:
{{{#!python
# create instance
o, c = A.objects.get_or_create(a='something', b=""another"")
print(o.a, o.b, c)

# find it with filter
o, c = A.objects.filter(a='something').get_or_create(b=""another"")
print(o.a, o.b, c)

# delete it again
A.objects.all().delete()

# create it with filter
o, c = A.objects.filter(a='something').get_or_create(b=""another"")
print(o.a, o.b, c)
}}}

Will output:
{{{
('something', 'another', True)
('something', 'another', False)
('', 'another', True)
}}}

This seems rather inconsistent, and should at least be flagged in the docs. "	New feature	closed	Database layer (models, ORM)	3.2	Normal	wontfix			Unreviewed	0	0	0	0	0	0
