Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
django_problem.py
### 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)
@AdrianRibao

This comment has been minimized.

Copy link

@AdrianRibao AdrianRibao commented May 11, 2010

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.

@javisantana

This comment has been minimized.

Copy link
Owner Author

@javisantana javisantana commented May 12, 2010

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