when ensuring model unique, check id not obj

this should fix an issue where we were attaching a suffix to non-duplicate
names on sync
This commit is contained in:
Damien Elmes 2013-10-05 23:53:09 +09:00
parent f23392b6a3
commit f1837e7e0a
2 changed files with 5 additions and 3 deletions

View file

@ -167,8 +167,10 @@ select id from cards where nid in (select id from notes where mid = ?)""",
self.save(m)
def ensureNameUnique(self, m):
if m['name'] in self.allNames(m):
m['name'] += "-" + checksum(str(time.time()))[:5]
for mcur in self.all():
if (mcur['name'] == m['name'] and
mcur['id'] != m['id']):
m['name'] += "-" + checksum(str(time.time()))[:5]
def update(self, m):
"Add or update an existing model. Used for syncing and merging."

View file

@ -100,7 +100,7 @@ def test_models():
time.sleep(1)
deck1.models.save(cm)
deck1.save()
assert deck2.models.get(cm['id'])['name'] == "Basic"
assert deck2.models.get(cm['id'])['name'].startswith("Basic")
assert client.sync() == "success"
assert deck2.models.get(cm['id'])['name'] == "new"
# deleting triggers a full sync