From 4e733ec604126cfc8b36ce0e3ef012127d53ad41 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 21 Aug 2023 19:59:51 -0400 Subject: [PATCH] simplify + preserve existing behavior better (ie utf-8 works :P) --- src/google/appengine/ext/ndb/model.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/google/appengine/ext/ndb/model.py b/src/google/appengine/ext/ndb/model.py index 9ccf0aa..834665e 100755 --- a/src/google/appengine/ext/ndb/model.py +++ b/src/google/appengine/ext/ndb/model.py @@ -2741,10 +2741,9 @@ def _db_get_value(self, v, p): sval = modelclass._from_pb(pb) elif meaning != entity_pb2.Property.BYTESTRING: try: - if six.PY2: - sval.decode('ascii') - elif meaning == entity_pb2.Property.TEXT: - sval = 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'))