#24912: prefetch_related fails with sqlite3 database and UUIDField primary keys
----------------------------------------------+-----------------------
     Reporter:  brki                          |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.8
     Severity:  Normal                        |   Keywords:  UUIDField
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+-----------------------
 Here's a test.py that fails on sqlite3, but succeeds if run on postgresql:

 {{{
 import uuid
 from django.db import models
 from django.test import TestCase


 class Award(models.Model):
     id = models.UUIDField(primary_key=True, default=uuid.uuid4)
     name = models.CharField(max_length=20)


 class Player(models.Model):
     id = models.UUIDField(primary_key=True, default=uuid.uuid4)
     name = models.CharField(max_length=20)
     awards = models.ManyToManyField(Award)


 class UUIDSqliteDemo(TestCase):
     def setUp(self):
         awards = [
             Award.objects.create(name='star'),
             Award.objects.create(name='trophy'),
         ]
         player = Player.objects.create(name='Beth')
         player.awards.add(*awards)
         self.player_id = player.id

     # This test passes if the target database is Postgresql, but fails for
 sqlite3:
     def test_prefetch_related(self):
         players =
 list(Player.objects.filter(id=self.player_id).prefetch_related('awards'))
         player = players[0]
         # For sqlite3, this fails with "2 != 0":
         self.assertEqual(2, len(player.awards.all()))
 }}}

 I also tried using a CharField instead of a UUIDField as the pk field;
 that worked fine.  So it seems to be a problem with the UUIDField and
 sqlite3 (or perhaps all non-Postgresql dbs?).

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

Reply via email to