[Bug]: [python] Reading a model property detaches the container previously returned by __getitem__, dropping mutations
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Bắt đầu với _RestField.__get__ trong packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 và các bài kiểm thử thất bại được mô tả trong packages/http-client-python/tests/unit/test_model_base_serialization.py. Kiểm tra cách các giá trị dạng list và dict được giải tuần tự hóa và lưu trong obj._data; tái hiện thứ tự truy cập dict trước rồi đến thuộc tính. Công việc hoàn tất khi các thay đổi thông qua tham chiếu mapping lấy được trước đó xuất hiện trong as_dict() và quá trình tuần tự hóa request, đồng thời các bài kiểm thử hiện có vẫn chạy thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
In the Python emitter's generated model runtime (_utils/model_base.py, from packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2), _RestField.__get__ deserializes list, dict and set values. It then stores the new container back into obj._data[rest_name] and sets _deserialized_<rest_name>.
Any container a caller got earlier through mapping access (obj["rest_name"]) is now detached from the model, so later mutations through that reference are silently dropped from as_dict() and request serialization. No error is raised.
The problem is limited to mixing dict access and property access on the same field. Mutating through a property reference (model.field.append(...)) works correctly; the property caching fixed that, since older generated runtimes lost those mutations. The remaining gap is the dict-then-property order:
| Access order | Mutation kept? |
|---|---|
| dict → property → mutate dict ref | ❌ lost |
| property → dict → mutate property ref | ✅ |
| property → mutate | ✅ |
| dict → mutate | ✅ |
| property → property → mutate first ref | ✅ |
Lists of models aren't affected: their deserializer returns the original list. Lists and dicts of primitives (for example list[str], dict[str, str]) are affected.
Expected: mapping access and property access share one backing container, so a mutation through either reference serializes.
Reproduction
Failing unit tests: https://github.com/microsoft/typespec/pull/12359 (adds to packages/http-client-python/tests/unit/test_model_base_serialization.py). 2 new tests fail, the guard and existing tests pass:
FAIL test_list_getitem_reference_survives_attribute_access: assert ['.txt'] == ['.txt', '.csv']
FAIL test_dict_getitem_reference_survives_attribute_access: assert {'a': '1'} == {'a': '1', 'b': '2'}
Equivalent with a minimal hand-written model:
from specialwords._utils.model_base import Model, rest_field # any generated package's model_base
class M(Model):
tags: list[str] = rest_field()
m = M(tags=["a"])
ref = m["tags"]
_ = m.tags
ref.append("b")
assert m.as_dict()["tags"] == ["a", "b"] # fails: ['a']
Checklist
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
- Ngôn ngữ chính
- Java
- Star
- 5.9k
- Fork
- 421
- Merge trung bình
- 2 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 176
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/typespec
-
bug emitter:client:csharp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/typespec#12572 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Make website build cross-platform compatibleCó thể đã có người làm @pcbeingused333 đã nhận hôm nay. Đang mởbug meta:website
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
microsoft/typespec#12550 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Emitter framework: make the language-specific Alloy peer dependencies optionalCó thể đã có người làm @timotheeguerin đã nhận 8 ngày trước. Đang mởemitter-framework feature triaged:core
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
microsoft/typespec#12476 · 1 bình luận · 2 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Upgrade C# generator Roslyn to 5.9.0Có thể đã có người làm @ArthurMa1978 đã nhận 7 ngày trước. Đang mởemitter:client:csharp feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
microsoft/typespec#12445 · 2 bình luận · 1 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: http-client-js reports `unknown-encoding` for a raw `bytes` bodyCó thể đã có người làm @Roxen-AS đã nhận 21 ngày trước. Đang mởbug emitter:client:js
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
microsoft/typespec#12356 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/typespec
Issue tương tự
-
GCC 15.2: -Wcast-qual warning - cast discards const qualifier from pointer target type (H5trace.c)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] RemotingHelper.connect swaps the socket send and receive buffer configurationCó thể đã có người làm @amalsaidov đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
area/ai area/backend component/zeebe kind/task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
spAnser/reacharound#38 ·