Using F objects raise an exception when calling save
Closed this issue · 6 comments
mounirmesselmeni commented
ValidationError
[u"'F(field_name) + Value(1)' value must be an integer."]
dirtyfields/dirtyfields.py ? in _as_dict
if field.rel:
if not check_relationship:
continue
field_value = getattr(self, field.attname)
all_field[field.name] = field.to_python(field_value) #This line
romgar commented
Hi @mounirmesselmeni , can you give some related code please ? The model you have defined, ...
mounirmesselmeni commented
@romgar Use any model this does not matter, just try to use F object and call save method
from django.db import models
from dirtyfields.dirtyfields import DirtyFieldsMixin
class TestModel(DirtyFieldsMixin, models.Model):
counter = models.IntegerField(default=0)
name = models.CharField(max_length=250)
Run this:
instance = TestModel.objects.all().first()
from django.db.models import F
instance.counter = F('counter') + 1
instance.save()
ValidationError: [u"'F(counter) + Value(1)' value must be an integer."]
This is a regression on the 0.6 release
romgar commented
Not a so usual case. Will deal with it.
mounirmesselmeni commented
Yeah but it's a regression related to calling to_python.
bf7a637#diff-03d4c5a503f183e4ca7f22ee6904bc06R24
romgar commented
Yep. Caught.
romgar commented
@mounirmesselmeni I have tried a naive approach to resolve it #40. If anybody has a better idea, feel free to propose :-)