Rows.as_trees(render=True) broken

83 views
Skip to first unread message

Leonel Câmara

unread,
Apr 29, 2015, 1:44:44 PM4/29/15
to web2py-d...@googlegroups.com
It seems the changes to render have broken as_trees. My application using as_trees with render=True has stopped working. Now it only works if I set a represent to the parent_id field (something like lambda ref,row: ref).  
  
This seems a bug as Fields that don't have a represent should just render their value.  
  
Can someone explain to me what changes to render could have caused this?

Niphlod

unread,
Apr 29, 2015, 4:51:22 PM4/29/15
to web2py-d...@googlegroups.com
uhm. this should have been fixed already (was the whole point of shipping 15.03-maintenace)

https://github.com/web2py/pydal/issues/135

gi0baro, can you look into it ?

Leonel Câmara

unread,
Apr 29, 2015, 5:04:55 PM4/29/15
to web2py-d...@googlegroups.com
Oh, my bad then, I was testing in 2.10.4

Giovanni Barillari

unread,
Apr 29, 2015, 5:44:59 PM4/29/15
to web2py-d...@googlegroups.com
if you was testing 2.10.4 then it should work.

I will try to investigate this.

/Giovanni

Giovanni Barillari

unread,
Apr 29, 2015, 5:58:21 PM4/29/15
to web2py-d...@googlegroups.com
Hmm, I see that render() function check if fields have a 'represent':
https://github.com/web2py/pydal/blob/master/pydal/objects.py#L2643

But it was the same even before the modular DAL:

@niphlod: Any ideas?

Leonel Câmara

unread,
Apr 29, 2015, 9:35:29 PM4/29/15
to web2py-d...@googlegroups.com
Humm after investigating I think I have found the cause.

The error starts in auto_represent somewhere around here:


The problem is that _repr_ref using _fieldformat is turning the referenced id into a string. Then as_trees has a problem because when a record doesn't have a parent you get 'None' yes a string with None written there.

Then this happens in as_trees:

if parent is None:
roots.append(row)
else:
drows[parent][children_name].append(row)


Well parent is not None, it's 'None' so it goes to the else and you get a KeyError: 'None' 

So I think this can be easily fixed by changing the line to: 

if parent in (None, 'None'): # Parent will be a string with None if it was rendered

Is this solution py3 compatible?

Massimo DiPierro

unread,
Apr 29, 2015, 11:06:43 PM4/29/15
to web2py-d...@googlegroups.com
why does it happen? A parent should not be ‘None’ but None.

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Apr 30, 2015, 8:12:16 AM4/30/15
to web2py-d...@googlegroups.com
I've explained in my previous post Massimo. The problem starts in auto_represent. I guess another solution would be for _fieldformat to return None instead of a string with None if the value is None. 

Giovanni Barillari

unread,
Apr 30, 2015, 8:27:25 AM4/30/15
to web2py-d...@googlegroups.com

Indeed. I will patch it right now.

Il 30/apr/2015 14:12, "Leonel Câmara" <leonel...@gmail.com> ha scritto:
I've explained in my previous post Massimo. The problem starts in auto_represent. I guess another solution would be for _fieldformat to return None instead of a string with None if the value is None. 

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py-developers/9I2uBKH90bM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py-develop...@googlegroups.com.

Giovanni Barillari

unread,
Apr 30, 2015, 9:18:08 AM4/30/15
to web2py-d...@googlegroups.com

Leonel Câmara

unread,
Apr 30, 2015, 9:36:43 AM4/30/15
to web2py-d...@googlegroups.com
Thanks Giovanni

Massimo DiPierro

unread,
Apr 30, 2015, 10:31:55 AM4/30/15
to web2py-d...@googlegroups.com
thanks everybody.

On Apr 30, 2015, at 8:36 AM, Leonel Câmara <leonel...@gmail.com> wrote:

Thanks Giovanni

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages