#31295: required ModelChoiceField makes duplicate (cursor) queries to the database -------------------------------------+------------------------------------- Reporter: Aurélien Pardon | Owner: nobody Type: | Status: closed Cleanup/optimization | Component: Forms | Version: 2.2 Severity: Normal | Resolution: needsinfo Keywords: Model | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Aurélien Pardon): Replying to [comment:4 Carlton Gibson]: > (Yes there's an extra query but correctness trumps performance.) How is that correct if the queries yield different results ? It only works if the two requests are inside a transaction, for example when {{{ATOMIC_REQUESTS}}} is set to {{{True}}} (which is not the default). For example, imagine this model (the primary key is important, it's the value that the choice will use): {{{#!python class MyModel(models.Model): my_field = models.CharField(max_length=1, primary_key=True) }}} If the first query (for the actual choices) returns {{{['a', 'b']}}}, but the second one (for the required attribute) returns {{{['', 'b', 'c']}}}, then the required attribute will be used leading to invalid HTML. -- Ticket URL: <https://code.djangoproject.com/ticket/31295#comment:5> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.55196005e4a05c9c23c7333ff1ddd832%40djangoproject.com.