Created
May 11, 2010 18:42
-
-
Save javisantana/397669 to your computer and use it in GitHub Desktop.
django_problem.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### models.py | |
class UserKarma(models.Model): | |
DEFAULT_KARMA = 10.0 | |
user = models.OneToOneField(User, primary_key=True, related_name='karma') | |
value = models.FloatField(default=DEFAULT_KARMA) | |
def change(self, qty, reason='no reason'): | |
v = self.value + qty | |
self.value = v | |
self.save() | |
### tests.py | |
def test_OK(self): | |
initial_karma = self.user2.karma.value | |
self.user2.karma.change(2) | |
self.failUnless(initial_karma < self.user2.karma.value) | |
def test_FAIL(self): | |
initial_karma = self.user2.karma.value | |
k = UserKarma.objects.filter(user=self.user2)[0] | |
k.change(2) | |
self.failUnless(initial_karma < self.user2.karma.value) | |
Sí, es cosa de la caché que guarda user. El ticket en concreto que comenta esto es el #17
Muhcas gracias
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yo creo que es un problema de caché, hasta donde yo se no se puede modificar en las querysets, y hay algunos tickets abiertos al respecto. http://code.djangoproject.com/ticket/7338
Puedes comprobar usando pdb, si justo antes de la línea 28 si initial_karma == self.user2.karma.value, yo creo que si. Entonces el problema de caché estaría confirmado.
Tambien puedes probar a poner antes de la línea 28:
after_karma = self.user2.karma.value
y ver que valor obtienes ahora.