Clone doesn't work as expected

Offen
#86 1 Kommentar 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@benoitc arbeitet bereits daran.

Seit 05.5.2011.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
261
Forks
90
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus benoitc/couchdbkit

Alle Issues in benoitc/couchdbkit

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.