googleapis / googleapis/google-cloud-python

google-cloud-ndb: Expando dynamic property updates are not persisted by put()

Đang mở
#18,204 1 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
5.4k
Fork
1.8k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
122

Mô tả

`google-cloud-ndb==2.3.0`, Python 3.11.

If I assign a dynamic property on an Expando and `put()`, the first write sticks. Changing that same property later and `put()` again looks fine (no error; in-process it even reads as the new value) but a refetch from datastore still has the old number.

Declared properties on the class (e.g. `FloatProperty`) update correctly. This also worked on the old App Engine ndb.

```python
from google.cloud import ndb

class Item(ndb.Expando):
name = ndb.StringProperty()

# ndb client context already active
ent = Item(name="x")
ent.extra = 2.00
key = ent.put()

ent = key.get()
ent.extra = 9.99
ent.put()

ent = key.get()
print(ent.extra) # 2.00, expected 9.99
```

`Expando.__setattr__` looks like the cause. If the name is already in `_properties` it calls `super().__setattr__`. For a class-level Property that hits the descriptor and updates `_values`. For a dynamic name there is no descriptor on the class, so it lands in `__dict__` and `put()` serializes the stale `_values`.

Is this expected? I couldn't find it documented. The old runtime always went through `_set_value` for non-class names.

Opened here because https://github.com/googleapis/python-ndb is archived.

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

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

Hướng nghiên cứu

Start with google-cloud-ndb's Expando.__setattr__ entry point and follow its _properties, _values, and _set_value handling. Reproduce the two-put example, then add or update a regression test showing that changing a dynamic property persists after refetch while declared properties continue to update correctly.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
google-cloud, python
Lĩnh vực
backend, databases
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
70/100

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.