retrieving json field from db (GAE)

36 views
Skip to first unread message

Carl Hunter Roach

unread,
Mar 1, 2019, 7:17:44 AM3/1/19
to web2py-users
In a db table I have:

Field('address', 'json', custom_qualifier={'indexed':False}

I retrieve an entry thus:

geo_address_row = db(db.geo_address.latlonkey == latlonkey).select(db.geo_address.latlonkey).first()


I could access the json data via `geo_address_row.address` as a dict.

but then I updated from web2py v2.14.6 to v2.18.2

and `geo_address_row.address` is now a str rather than a dict and I need to wrap it thus: `json.loads(geo_address_row.address)`

I suspect I've been living with an error that has, by undefined chance, worked; and that Web2py has now closed that bug and caught me out.

Have I given enough information for anyone to provide an insight?

Leonel Câmara

unread,
Mar 1, 2019, 2:28:22 PM3/1/19
to web2py-users
This is probably pyDAL bug, you should still get a dictionary. I say probably because I don't really use google app engine, and there's a chance that json was not supported at the time and so web2py used a text field and then made the conversion, and, nowadays it may be supported in which case it doesn't need to do the json parsing.

To fix this issue for yourself edit gluon/packages/dal/pydal/parsers/google.py to look like this

from ..adapters.google import GoogleDatastore
from .base import BasicParser, JSONParser
from . import parsers, for_type


@parsers.register_for(GoogleDatastore)
class GoogleDatastoreParser(BasicParser, JSONParser):
   
@for_type('id')
   
def _id(self, value):
       
return value

   
@for_type('boolean')
   
def _boolean(self, value):
       
return value

I would make a pull request with the fix, but, as I said, I'm not even sure this is a bug due to lack of familiarity with GAE. If you can confirm that this is a bug on our side (e.g. make a brand new GAE web2py application with json fields and check that they also return strings instead of a dict), then I'll gladly fix it in github.


Massimo Di Pierro

unread,
Mar 3, 2019, 3:09:13 AM3/3/19
to web2py-users
if we broke this, it was not intentional. Please open a ticket about this so we can track it. It will be fixed asap

Carl Hunter Roach

unread,
Mar 4, 2019, 11:33:09 AM3/4/19
to web...@googlegroups.com
hi Leonel.

I'm not added a Web2py/Pydal github-collabator but I have made your suggested changes to a copy of PyDal and those changes did address my problem.

I added an issue as requested:

but now I've tried out the fix I see that I should have posted to pydal instead. Apologies for that.


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/lstHGGuaBR8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Carl Hunter Roach

Founder of Midnight 30
Jobs at great companies you can commute to.
Reply all
Reply to author
Forward
0 new messages