Clone doesn't work as expected

Đang mở
#86 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

@benoitc đang làm issue này rồi.

Từ ngày 5/5/2011.

Đánh giá

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

Mô tả

improvment Need Feedback

Just to note, this issue was in couchdbkit before the recent changes to clone. And it's still here after the recent commits.
(It just so happens that this affected me at around the same time!)

Also I am not sure if this is an issue or bug, or if its unexpected behaviour.

>>> from couchdbkit import *
>>> class Person(Document):
...     name = StringProperty()
...     
>>> person_one = Person()
>>> person_two = person_one.clone()
>>> person_one.name = 'XYZ'
>>> person_two.name
u'XYZ'
>>> person_one
<__main__.Person object at 0x027EA170>
>>> person_two
<__main__.Person object at 0x04562530>

As you can see. If I change a property in person_one it is changing all the names for anything that was cloned from person_one, even though the new object coming back from clone() is a brand new object.
It just seems it's only making a copy of the Document object, while the property objects inside the new copy are still pointing to the old property objects.

I have tried copy and deepcopy from the copy module;
copy runs, but I get the same result.
deepcopy throws an error.

I am using the latest version of couchdbkit.

Thanks.

Ngôn ngữ chính
Python
Star
261
Fork
90
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của benoitc/couchdbkit

Tất cả issue của benoitc/couchdbkit

Issue tương tự

Thêm issue về Python

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.