#24912: prefetch_related fails with sqlite3 database and UUIDField primary keys
-------------------------------------+-------------------------------------
     Reporter:  brki                 |                    Owner:  zedr
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  UUIDField            |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by zedr):

 Interestingly, clearing the `prefetch_related` behavior does not fix the
 problem:

 {{{
 >>> players = Player.objects.filter(id=self.player_id)
 >>> # Enable prefetching
 >>> players = players.prefetch_related('awards')
 >>> # Disable prefetching (before the queryset is evaluated)
 >>> players.prefetch_related(None)
 >>> player = players.get()
 >>> # For sqlite3, this fails with "2 != 0":
 >>> self.assertEqual(2, len(player.awards.all()))

 (0.000) QUERY = 'SELECT "model_fields_player"."id",
 "model_fields_player"."name" FROM "model_fields_player" WHERE
 "model_fields_player"."id" = %s' - PARAMS =
 ('9674a6f11c044484b89bac792e53e642',);
 args=('9674a6f11c044484b89bac792e53e642',)

 (0.000) QUERY = 'SELECT ("model_fields_player_awards"."player_id") AS
 "_prefetch_related_val_player_id", "model_fields_award"."id",
 "model_fields_award"."name" FROM "model_fields_award" INNER JOIN
 "model_fields_player_awards" ON ( "model_fields_award"."id" =
 "model_fields_player_awards"."award_id" ) WHERE
 "model_fields_player_awards"."player_id" IN (%s)' - PARAMS =
 ('9674a6f11c044484b89bac792e53e642',);
 args=('9674a6f11c044484b89bac792e53e642',)
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24912#comment:6>
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/062.506d9bf8e61f8ded0d6af7504f5985ac%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to