What version are you running?
0.5.6
What's the URL of the page containing the problem?
This is an intranet application - not available on public domain.
What steps will reproduce the problem?
1. Create any class derived from django.db.models
2. Define the primary key explicitly, column name has to be different than
that the default 'id', for instance:
class OneRepFileDiffInfo(models.Model):
diff = models.OneToOneField(FileDiff, primary_key=True)
base_name = models.CharField(_("Base Name"),max_length=100)
3. Use the class defined as above for the display based on DataGrid:
class OneRepReviewRequestConfirmationDataGrid(DataGrid):
..
def __init__(self, request):
DataGrid.__init__(self, request,
OneRepFileDiffInfo.objects.filter(diff__in=ids))
What is the expected output? What do you see instead?
The Grid should be properly renedered, but we get the AttributeError
exception instead:
Traceback (most recent call last):
File
"C:\Python26\lib\site-packages\django-1.1.1-py2.6.egg\django\core\handlers\base.py",
line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "D:\workspace-codereview\ocr\reviewboard\onerepapp\views.py", line
88, in review_confirmation
return
OneRepReviewRequestConfirmationDataGrid(request).render_to_response(template_name)
File
"C:\Python26\lib\site-packages\djblets-0.5.6-py2.6.egg\djblets\datagrid\grids.py",
line 680, in render_to_response
self.load_state()
File
"C:\Python26\lib\site-packages\djblets-0.5.6-py2.6.egg\djblets\datagrid\grids.py",
line 516, in load_state
self.precompute_objects()
File
"C:\Python26\lib\site-packages\djblets-0.5.6-py2.6.egg\djblets\datagrid\grids.py",
line 608, in precompute_objects
object_list[index[obj.id]] = obj
AttributeError: 'OneRepFileDiffInfo' object has no attribute 'id'
What operating system are you using? What browser?
The app is runninng on test PC (WinXP), but in this case neither OS nor the
browser would matter - this is more about the way the 'object_list' get
populated in the precompute_objects callback.
Please provide any additional information below.
From the previous section in the same method I can see the proper usage of
the pk metaname while pupulating the 'self.id_list':
self.id_list = list(self.page.object_list.distinct().values_list(
'pk', flat=True))
.. and then all of the sudden the 'id' attribute is used explicitly instead
when ordering the list:
for obj in list(self.page.object_list):
object_list[index[obj.id]] = obj
Please find the attached patch - simple replacement of the explicit id
reference with the pk metaname fixes the problem sufficiently.