diff --git a/src/google/appengine/ext/ndb/model.py b/src/google/appengine/ext/ndb/model.py index 4671662..834665e 100755 --- a/src/google/appengine/ext/ndb/model.py +++ b/src/google/appengine/ext/ndb/model.py @@ -2741,8 +2741,9 @@ def _db_get_value(self, v, p): sval = modelclass._from_pb(pb) elif meaning != entity_pb2.Property.BYTESTRING: try: - sval.decode('ascii') - + decoded = sval.decode('ascii') + if six.PY3 and meaning == entity_pb2.Property.TEXT: + sval = decoded except UnicodeDecodeError: try: sval = six.text_type(sval.decode('utf-8')) diff --git a/tests/google/appengine/ext/ndb/polymodel_test.py b/tests/google/appengine/ext/ndb/polymodel_test.py index 5608e57..515c154 100755 --- a/tests/google/appengine/ext/ndb/polymodel_test.py +++ b/tests/google/appengine/ext/ndb/polymodel_test.py @@ -143,9 +143,18 @@ class Mammal(Animal): self.assertEqual(cat1.naps, 18) self.assertEqual(cat1.sound, b'purr') - def testExpandoPoly(self): - + # un-indexed properties retain str type regardless of encoding: + Mammal._default_indexed = False + cat = Mammal(name='Clémentine', naps=18, sound=b'meow', action='stretch') + cat1 = cat.put().get(use_cache=False) + self.assertFalse(cat1 is cat) + self.assertEqual(cat1, cat) + self.assertEqual(cat1.name, 'Clémentine') + self.assertEqual(cat1.naps, 18) + self.assertEqual(cat1.sound, b'meow') + self.assertEqual(cat1.action, 'stretch') + def testExpandoPoly(self): class Animal(model.Expando, PolyModel): pass @@ -162,6 +171,18 @@ class Mammal(Animal): self.assertEqual(18, actual.naps) self.assertEqual(b'purr', actual.sound) + # un-indexed properties retain str type regardless of encoding: + Mammal._default_indexed = False + expected = Mammal(name='Clémentine', naps=18, sound=b'meow', action='stretch') + actual = expected.put().get() + + self.assertIsNot(expected, actual) + self.assertEqual(expected, actual) + self.assertEqual('Clémentine', actual.name) + self.assertEqual(18, actual.naps) + self.assertEqual(b'meow', actual.sound) + self.assertEqual('stretch', actual.action) + def testInheritance(self): class NamedThing(model.Model):