geier / pycarddav

DEPRECATED - use vdirsyncer & khard -- easy to use CLI CardDAV client
http://lostpackets.de/pycarddav
MIT License
98 stars 35 forks source link

merged local vcards are overwritten by server version #74

Closed jmcclelland closed 11 years ago

jmcclelland commented 11 years ago

When you merge a vcard with an existing vcard, the etag is set to empty (as if it was a new vcard). As a result, when sync'ing with the server, it is overwritten by the version on the server.

jmcclelland commented 11 years ago

I have a functional fix here:

https://git.mayfirst.org/?p=jamie/pycarddav.git;a=commitdiff;h=8d299508b91b7571630bf5ba7ba88b90d524f22e

However, I don't think it's the right fix. It might be better to fix ui.py so when merging, the etag and status are properly set when the update function is called? However, I'm not sure how to get the etag from ui.py.

geier commented 11 years ago

thanks for letting me know, sadly I won't have time to look at this until next week

geier commented 11 years ago

I went ahead and let VCard know its etag so it can be set during update. the bug should be fixed no, if the bug persists, please reopen this bug

jmcclelland commented 11 years ago

Thanks for changes!

Unfortunately,I'm still having problems. :(.

I see that you are using INSERT OR REPLACE INTO when updating account records, however, there is no primary key defined in the account table, so those always insert a new record with an empty etag. Then, updating with the server sees the empty etag and inserts a duplicate on every sync.

Unfortunately it appears as though you cannot add a primary key to an existing sqlite table so I just dumped my database, added the primary key in the dump and then re-create my sqlite database from the dump.

I've patched the code to add the primary key on new table creation.

In addition, we now have the etag on update, but the status is still hard-coded to NEW. I've fixed that as well by shoving a new attribute into the EditorPane class. Maybe there is a more elegant way? In any event, it seems to work.

Here's the patch: https://git.mayfirst.org/?p=jamie/pycarddav.git;a=commitdiff;h=9fd5504a518b07a130f773bd4531b63c69e7f9bd

geier commented 11 years ago

looks like I was in a bit of a rush to close this bug…

thanks for the patch, please add yourself to the CONTRIBUTORS.txt file

jmcclelland commented 11 years ago

Thanks :)

https://github.com/geier/pycarddav/issues/74#issuecomment-23676855

geier commented 11 years ago

merged. Thanks again!