Clone doesn't work as expected

Aperta
#86 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@benoitc ci sta già lavorando.

Dal 5/5/2011.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.

Lingua principale
Python
Stelle
261
Fork
90
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di benoitc/couchdbkit

Tutte le issue di benoitc/couchdbkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.