#34884: Half bug/half enhancement : inconsistent behavior of get_or_create()
regarding related attributes cache
-------------------------------------+-------------------------------------
     Reporter:  Laurent Lyaudet      |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  ORM get_or_create    |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Laurent Lyaudet):

 Hi Natalia, Hi Tim,

 I did what was needed : https://pypi.org/project/django-monkey-patches/

 Replying to [comment:6 Tim Graham]:
 > Hi Laurent,
 >
 > To echo what Natalian said, please avoid comments like "in case some
 bikeshedding occurs that puts to trash coherency and efficiency in yet
 another open source software where some people against free software have
 influence". It adds nothing helpful. Assuming bad faith on the part of the
 Django community is no way to introduce yourself and get people to want to
 work with you. Thank you.

 Sorry, that's the result of previous interactions with the FOSS community
 among which Django here:
 https://groups.google.com/g/django-developers/c/257nJTrf1Qk/m/7wz1AVj_AwAJ
 where the silence closed the discussion.

 > As for the issue, I think it's a bit of a niche case. I mocked up a
 patch using your proposal. I'm not sure that the extra complexity is
 worthwhile, as well as the performance penalty of iterating through the
 `kwargs` (which is unnecessary when a foreign key isn't present). The
 patch may need consideration for other relations like `GenericForeignKey`.
 I'm not sure offhand. I wonder if `update_or_create()` has a similar
 inconsistency.

 In my tests, as I previously said, there is a global performance gain of
 more than 7 % ! (for such a small patch), despite the very small penalty
 in some cases.
 There is several orders of magnitude between iterating over some kwargs
 and avoiding a DB query (a fortiori if you have an n-tiers architecture).
 `update_or_create()` is already patched since it uses `get_or_create()`
 internally:
 
https://github.com/django/django/blob/f7389c4b07ceeb036436e065898e411b247bca78/django/db/models/query.py#L967

 > I'm afraid that trying to make the ORM smarter about this might open a
 can of worms.
 FUD, if it's not precise, it's not constructive and does not help having a
 clear view of the question.
 Maybe you do not it intentionally, but maybe you do, I can't know.
 https://en.wikipedia.org/wiki/Fear,_uncertainty,_and_doubt

 Replying to [comment:5 Natalia Bidart]:
 >Laurent, first of all, please maintain a professional tone and adhere to
 the ​Django Code of Conduct when composing/sending messages.
 Yes but it says "This code applies equally to founders, mentors and those
 seeking help and guidance."
 And closing my ticket without an open discussion before is a kind of slap
 in the face that is unfortunately current on the Internet.
 It says also "Be friendly and patient", "Be welcoming", "Be considerate",
 "Be respectful".
 I'm not the only one who does not strictly followed this code of conduct
 here.

 > Secondly, if you disagree with this resolution, you are welcomed to
 follow ​the documentation and start a new conversation on the ​Django
 Forum, where you'll reach a wider audience and likely get more feedback.
 Well if the forum is as responsive as the dev google-group...
 Sorry, I like truth and progress, my energy can bring a lot of good to the
 world, but it cannot overcome people that do not want to try to see the
 problem at hand like me for 5 minutes.

 Best regards,
 Laurent Lyaudet

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34884#comment:7>
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/0107018bbf0918c5-de7ee4bf-39ce-4ccb-8389-bd64f1d0074e-000000%40eu-central-1.amazonses.com.

Reply via email to