GoogleCloudPlatform / GoogleCloudPlatform/appengine-python-standard

GenericProperty (and therefore Expando) changes str values to bytes (sometimes)

Đang mở
#99 3 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
86
Fork
61
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## Expected Behavior

If I set the value of a GenericProperty to a `str`, then read it back from datastore, the value should still always be a `str`. The value I read back should equal the value I put in.

## Actual Behavior

If I set a GenericProperty to the string `'oops'`, then read it back from datastore, the value is now `b'oops'`, so it is not equal to the value I put in the property.
If I set a GenericProperty to the string `'oøps'`, then read it back from datastore, the value is still `'oøps'`. Apparently we are deciding to do different behavior depending on the contents of the string.

The same thing happens in appengine Python 2 incidentally, but it was not a big problem in practice because in Python 2, `'oops' == u'oops'` was `True`. In Python 3 it is a problem :)

## Steps to Reproduce the Problem

```
class Oops(ndb.Model):
generic_prop = ndb.GenericProperty()
string_prop = ndb.StringProperty()

oops = Oops(generic_prop="oøps", string_prop="oøps")
assert "oøps" == oops.generic_prop == oops.string_prop
oops.put()
assert "oøps" == oops.generic_prop == oops.string_prop
oops = oops.key.get()
assert "oøps" == oops.generic_prop == oops.string_prop
oops = oops.key.get(use_cache=False)
assert oops.generic_prop == oops.string_prop # <- Succeeds: both properties are still "oøps"

oops = Oops(generic_prop="oops", string_prop="oops")
assert "oops" == oops.generic_prop == oops.string_prop
oops.put()
assert "oops" == oops.generic_prop == oops.string_prop
oops = oops.key.get()
assert "oops" == oops.generic_prop == oops.string_prop
oops = oops.key.get(use_cache=False)
assert oops.generic_prop == oops.string_prop # <- Fails, because now generic_prop is b'oops'
```

## Specifications

- Version: appengine-python-standard 1.1.3, Python 3.11.4
- Platform: MacOS

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.