#22728: get_or_create with field lookups cause empty values
-------------------------------------+-------------------------------------
Reporter: Xudonax | Owner: coldmind
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: get_or_create | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by carljm):
FWIW, I have code in a current project, written only a few months ago,
that uses join lookups with `get_or_create`, and takes advantage of the
fact that they are used in the lookup but not the create. I don't think
it's an exotic use case, it's simply "find me a user that matches these
criteria, where the criteria are actually based on related objects, and if
no such user exists, create a user with the given defaults." That's
exactly the use case that `get_or_create` is intended for, with the
addition of "the criteria are based on related objects."
Even requiring any field mentioned in a lookup to be present in defaults
is potentially a backwards-incompatible breakage to such use cases. I
don't know how that change would even handle my case, as the relation I'm
querying on is not even a field present on User, it's a reverse FK from
another model, so there's no sensible corresponding value that could be
included in defaults.
I see the possible confusion here, but I don't see any way to address it
without reducing the utility of `get_or_create` in a backwards-
incompatible way. So I think we should make sure the documentation of
`get_or_create` is crystal clear on this point, and otherwise leave the
behavior alone.
--
Ticket URL: <https://code.djangoproject.com/ticket/22728#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.e2bb63c1cc3fccb0df2563cd5941a3b9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.