#29913: Issue with ForeignKey to model with non-abstract base class and UUID-pk
-------------------------------------+-------------------------------------
Reporter: Alexei Komissarov | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Alexei Komissarov):
Models:
{{{
import uuid
from django.db import models
class Vehicle(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
editable=False)
created_date = models.DateTimeField(verbose_name="Created date",
auto_now_add=True)
class CarVehicle(Vehicle):
name = models.CharField("Name", max_length=255)
class Item(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
editable=False)
car = models.ForeignKey(
CarVehicle, related_name="items", on_delete=models.PROTECT)
}}}
Test:
{{{
from django.test import TestCase
from testbed.models import CarVehicle, Item
class CrashTest(TestCase):
def setUp(self):
car = CarVehicle.objects.create(name="test")
Item.objects.create(car=car)
def test_error(self):
cars = CarVehicle.objects.all().prefetch_related("items")
for car in cars:
print(len(list(car.items.all())))
}}}
Exception:
{{{
ERROR: test_error (tests.CrashTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Source\InMeta.py\inmeta\testbed\tests.py", line 13, in
test_error
for car in cars:
File "C:\Source\InMeta.py\inmeta\venv\lib\site-
packages\django\db\models\query.py", line 268, in __iter__
self._fetch_all()
File "C:\Source\InMeta.py\inmeta\venv\lib\site-
packages\django\db\models\query.py", line 1188, in _fetch_all
self._prefetch_related_objects()
File "C:\Source\InMeta.py\inmeta\venv\lib\site-
packages\django\db\models\query.py", line 723, in
_prefetch_related_objects
prefetch_related_objects(self._result_cache,
*self._prefetch_related_lookups)
File "C:\Source\InMeta.py\inmeta\venv\lib\site-
packages\django\db\models\query.py", line 1569, in
prefetch_related_objects
obj_list, additional_lookups = prefetch_one_level(obj_list,
prefetcher, lookup, level)
File "C:\Source\InMeta.py\inmeta\venv\lib\site-
packages\django\db\models\query.py", line 1682, in prefetch_one_level
prefetcher.get_prefetch_queryset(instances,
lookup.get_current_queryset(level)))
File "C:\Source\InMeta.py\inmeta\venv\lib\site-
packages\django\db\models\fields\related_descriptors.py", line 611, in
get_prefetch_queryset
instance = instances_dict[rel_obj_attr(rel_obj)]
KeyError: ('de3dacc26c974743b3fe91ae2cb291ab',)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29913#comment:2>
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/066.fa0c80768b372b5b2082faf303de7ca3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.