do cell skips the first cell

Bug #681113 reported by David Burke
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Appy
Won't Fix
Undecided
Unassigned

Bug Description

I have a 3 column table. I put do cell for student in students as a note. I would expect it to fill in each cell with the fields as in
http://appyframework.org/podWritingTemplates.html
However instead the first cell is blank. There is also an extra cell at the end containing any non field text.

Revision history for this message
David Burke (bufke) wrote :
Revision history for this message
David Burke (bufke) wrote :
  • bug.odt Edit (10.9 KiB, application/vnd.oasis.opendocument.text)
Revision history for this message
Gaëtan Delannay (gaetan-delannay) wrote :

Hi,
I've attached a version of Appy that solves the problem of having cells containing only your "raw", non-pod-expression, cell content.
But I can't reproduce the bug where the first cell is empty. Could you give me more information about your environment:
- OS
- Python version ?

Thanks,
Gaetan Delannay

Revision history for this message
David Burke (bufke) wrote :

I can confirm the patch fixes the raw text at the end. I'm still getting an empty cell at the beginning.
Ubuntu 10.10 x86_64
Python 2.6.6

Revision history for this message
Gaëtan Delannay (gaetan-delannay) wrote :

Hi, could you send me an example of result ODT file containing the leading empty cell?
Thanks,
Gaetan

Revision history for this message
David Burke (bufke) wrote :
  • after.odt Edit (10.5 KiB, application/vnd.oasis.opendocument.text)

Here is the resultant file. But I was playing around with it more and discovered it only happens to Django model instances.

This works without any blank cell.

class struct(object): pass # A very simple python class, similar to a c++ struct
student = struct()
student.lname = "lname"
student.fname = "fname"
data['students'] = []
data['students'].append(student)
renderer = Renderer(template, data, filename)

This results in a blank cell.
data['students'] = Student.objects.all()
renderer = Renderer(template, data, filename)

These lines of code prove the appy should print out only 1 cell, not one blank and one with data.
>>> students = Student.objects.all()
>>> for student in students:
... print student
...
Student, Test
>>>

hmm. I made a new Django model from scratch just to verify the problem. I could send you a sample Django project to show the bug if you'd like. It's pretty easy to demonstrate from the snippet above. I'm using Django 1.2.3

Revision history for this message
David Burke (bufke) wrote :

I just noticed it doesn't just create a blank cell, it moves the cells in the first row to the right. It can thus hid data like this.

Expected
A | B | C
D | E | F

Bug
    | A | B (C is hidden)
 D | E | F

I looked around content.xml. C was in the file. But a <table:table-cell></table:table-cell> in the beginning caused it not to show. I removed this to find the odt file opened up perfectly.

Revision history for this message
David Burke (bufke) wrote :

Ok some more light on this issue, in actions.py

I though I was going insane debugging this, print self.exprResult on line 135 after iter(self.exprResult) fixed the problem! str(self.exprResult) works too. Deleting iter(self.exprResult) also fixes the problem. This is really over my head what's going on here. the str way seems the safest hack to fix this. I've attached the patch. Would be nice to know why it fixes it...I don't know how to test it further. Somehow the iter screws it up but doing anything to it fixes it? Furthermore it's something Django specific as far as I can tell.

Revision history for this message
Gaëtan Delannay (gaetan-delannay) wrote :

Hi David,

In your example, what is the type of variable "students" ?
student = Student.objects.all()

Can you print 'type(student)' or student.__class__.__name__ ? (or self.exprResult which holds the same I guess)

Can't you write smth like "list(students)" or "tuple(students)", to get a pure Python object to iterate?
Or write in a note "do ... for student in Student.objects" or ... or ...

Performing one more conversion like in your patch could slow down performance, and does not bring us the real explanation about the problem...

Thanks in advance
Gaetan

Revision history for this message
David Burke (bufke) wrote :

type(students)
<class 'django.db.models.query.QuerySet'>

students.__class__.__name__
'QuerySet'

I changed my odt template to say
do cell for student in iter(students)
This works.
From http://docs.djangoproject.com/en/dev/ref/models/querysets/

Iteration. A QuerySet is iterable, and it executes its database query the first time you iterate over it. For example, this will print the headline of all entries in the database:
for e in Entry.objects.all():
    print e.headline

iterator()
Evaluates the QuerySet (by performing the query) and returns an iterator over the results. A QuerySet typically caches its results internally so that repeated evaluations do not result in additional queries; iterator() will instead read results directly, without doing any caching at the QuerySet level. For a QuerySet which returns a large number of objects, this often results in better performance and a significant reduction in memory

Note that using iterator() on a QuerySet which has already been evaluated will force it to evaluate again, repeating the query.

So that's the difference between using iter() or not. Of course it still make little sense as to why we would ever see a blank in the former but not the later. Not sure what else to do here.

Changed in appy:
status: New → Won't Fix
Changed in appy:
milestone: none → 0.6.4
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.