#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):

 Using len():

 {{{
 >>> player_ = players.get()
 >>> 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 =
 ('f48b661fe6b1442f88098656204f3abf',);
 args=('f48b661fe6b1442f88098656204f3abf',)

 (0.000) QUERY = 'SELECT "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" = %s' - PARAMS =
 ('f48b661fe6b1442f88098656204f3abf',);
 args=('f48b661fe6b1442f88098656204f3abf',)
 }}}

 {{{
 >>> players = players.prefetch_related('awards')
 >>> 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 =
 ('f48b661fe6b1442f88098656204f3abf',);
 args=('f48b661fe6b1442f88098656204f3abf',)

 (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 =
 ('f48b661fe6b1442f88098656204f3abf',);
 args=('f48b661fe6b1442f88098656204f3abf',)
 }}}

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

Reply via email to