chillinc / CQLEngine-Session

BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Sequential increments of counter produces incorrect value #2

Open mviamari opened 10 years ago

mviamari commented 10 years ago

I added a counter test for this scenario. Here's the core of it:

instance.counter += 3
save()

instance.counter += 7
save()

instance.counter += 7
save()
clear()

new = TestCounterModel.get(partition=key)
assert new.counter == 17

FAIL: new.counter != 17, new.counter == 30

The actual final value is 30. What I think is happening is that CQLEngine applies all values of the counters as increments. Thus, when you do "setattr", if you use the current value of the counter, it treats it as a increment for the full value.

start: instance.counter = 0

instance.counter += 3  # current actual value is 3
save()  # CQLEngine increment by 3

instance.counter += 7 # current actual value is 10
save() # CQLEngine increment by 10, CQL value is 13

instance.counter += 7 # current actual value is 17
save() # CQLEngine increment by 17, CQL value is 30.

The problem is that when the "_dirties" are applied to the CQLEngine instance during save, it's using the full value of the counter column. It seems that CQLEngine implicitly converts this to an increment by that full value.