#19580: Unify reverse foreign key and m2m unsaved model querying
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: raydeal
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by raydeal):
My patch is implemented using different approach then previous. It changes
behaviour of FK to be the same as M2M.
I went through discussion in this and #17541 ticket and PR for them and
analysed examples.
This information in the ticket
" There is a (slightly stale) patch for #17541 which makes fk fields and
m2m fields work consistently."
may be true 9 years ago, but now it is not consistent with M2M.
I have also tested previous patch
(https://github.com/django/django/pull/13784) locally.
I couldn't find correct rules because M2M worked as always, only changed
behaviour of FK. When object is not saved it raises ValueError, when saved
but related value is Null returns <QuerySet []>, which is not consistent
for me. Why?
Base on doubt from #17541
https://code.djangoproject.com/ticket/17541#comment:8 I asked myself: What
is the difference between not saved object with id (pk) refrerenced from
other object and saved object with field containing Null value referenced
by other object, through FK both, from the relation point of view?
There is no difference - both of them have Null value and making related
query in both cases doesn't make sens.
So finally I came to the conclusion that what M2M is doing is correct - in
both cases it raises error - and it meet some of The Zen of Python rules,
I think :)
--
Ticket URL: <https://code.djangoproject.com/ticket/19580#comment:47>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.61fb75159e5a5926c248ed4ebc84bb48%40djangoproject.com.