Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PolyModels can't be retrieved from bdbdatstorage #13

Open
zutesmog opened this issue Sep 2, 2009 · 2 comments
Open

PolyModels can't be retrieved from bdbdatstorage #13

zutesmog opened this issue Sep 2, 2009 · 2 comments

Comments

@zutesmog
Copy link

zutesmog commented Sep 2, 2009

I have run into a problem now though with PolyModels
I can create them fine, however if I fetch the entity I get the
following error.

c1=psc.models.Course.all().fetch(1)[0]
c2=psc.models.Campus.all().fetch(1)[0]
c2

c1

cc = psc.models.CourseCampus(key_name="abc")
cc.src_id = str(c1.key())
cc.target_id = str(c2.key())
cc.src = c1
cc.target = c2
cc.put()
datastore_types.Key.from_path(u'Reference', u'abc',_app_id_namespace=u'psc-dev1')
xx = psc.models.CourseCampus.get_by_key_name("abc")
Traceback (most recent call last):
File "", line 1, in
File "/home/timh/google_appengine_1.2.4/google/appengine/ext/db/
init.py", line 900, in get_by_key_name
return get(*keys)
File "/home/timh/google_appengine_1.2.4/google/appengine/ext/db/
init.py", line 1105, in get
model = cls1.from_entity(entity)
File "/home/timh/google_appengine_1.2.4/google/appengine/ext/db/
polymodel.py", line 310, in from_entity
raise db.KindError('No implementation for class '%s'' % key)
TypeError: not all arguments converted during string formatting

Exactly the same code works fine with standard SDK datastore

@zutesmog
Copy link
Author

zutesmog commented Sep 2, 2009

The key and _class_map seem to have reversed keys .

304 if (_CLASS_KEY_PROPERTY in entity and
305 tuple(entity[_CLASS_KEY_PROPERTY]) != cls.class_key()):
306 key = tuple(entity[_CLASS_KEY_PROPERTY])
307 import pdb
308 pdb.set_trace()
309 -> try:
310 poly_class = _class_map[key]
311 except KeyError:
312 raise db.KindError('No implementation for class '%s'' % key)
313 return poly_class.from_entity(entity)
314 return super(PolyModel, cls).from_entity(entity)

(Pdb) key

(u'CourseCampus', u'Reference')

(Pdb) _class_map

{('Reference', 'CourseCampus'): <class 'psc.models.coursecampus.CourseCampus'>, ('Reference', 'UnitListUnitOfStudy'): <class 'psc.models.unitlistunitofstudy.UnitListUnitOfStudy'>, ('Reference',): <class 'psc.models.reference.Reference'>, ('Reference', 'Classification'): <class 'psc.models.classification.Classification'>}

@zutesmog
Copy link
Author

zutesmog commented Sep 2, 2009

Ok further investigation shows that the class attribute of the raw entity has the values order reversed when saved in bdbdatastore vs standard sdk. But on the entities creation before being saved the class attributes values are in the correct order.

x1 = psc.models.Course.all().get()
x2 = psc.models.Campus.all().get()
x3 = psc.models.CourseCampus(key_name="x1x2")
psc.models.CourseCampus.class_key()
('Reference', 'CourseCampus')

Later on retrieval of that record from bdbdatastore has the values reversed.

zz = psc.models.CourseCampus.get_by_key_name("x1x2")

/home/timh/google_appengine/google/appengine/ext/db/polymodel.py(309)from_entity()

-> try:

(Pdb) p key

(u'CourseCampus', u'Reference')

(Pdb) p entity

{u'src': datastore_types.Key.from_path(u'Course', u"(97868, u'0386')", _app_id_namespace=u'psc-dev1'), u'src_id': None, u'target': datastore_types.Key.from_path(u'Campus', u"(u'1304587',)", _app_id_namespace=u'psc-dev1'), u'created': datetime.datetime(2009, 9, 3, 0, 7, 46, 720900), u'reference_type': None, u'target_id': None, u'modified': datetime.datetime(2009, 9, 3, 0, 8, 38, 390370), u'class': [u'CourseCampus', u'Reference']}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant