Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeserializationError: can't revert object with F() function #848

Open
NguyenMinhDung opened this issue Sep 8, 2020 · 4 comments
Open

DeserializationError: can't revert object with F() function #848

NguyenMinhDung opened this issue Sep 8, 2020 · 4 comments

Comments

@NguyenMinhDung
Copy link

DeserializationError                      Traceback (most recent call last)
<ipython-input-20-775fb025c638> in <module>
      3 data = versions[1].serialized_data
      4 
----> 5 list(serializers.deserialize("json", data))

~/PycharmProjects/dicago/venv/lib/python3.8/site-packages/django/core/serializers/json.py in Deserializer(stream_or_string, **options)
     67     try:
     68         objects = json.loads(stream_or_string)
---> 69         yield from PythonDeserializer(objects, **options)
     70     except (GeneratorExit, DeserializationError):
     71         raise

~/PycharmProjects/dicago/venv/lib/python3.8/site-packages/django/core/serializers/python.py in Deserializer(object_list, using, ignorenonexistent, **options)
    143                     data[field.name] = field.to_python(field_value)
    144                 except Exception as e:
--> 145                     raise base.DeserializationError.WithData(e, d['model'], d.get('pk'), field_value)
    146 
    147         obj = base.build_instance(Model, data, using)

DeserializationError: ["'F(edits) + Value(1)' value must be an integer."]: (post:pk=1) field_value was 'F(edits) + Value(1)'.

I get the error when I try to revert to old version
Does anyone know the problem?

@etianen
Copy link
Owner

etianen commented Sep 8, 2020 via email

@NguyenMinhDung
Copy link
Author

I use F(edits) + Value(1) to increase edits field by 1 when I save obj to database.
When reversion capture my obj, It contains F(edits) + Value(1) after that I revert the version I receive the error.

@etianen
Copy link
Owner

etianen commented Sep 9, 2020 via email

@dytechgithub
Copy link

dytechgithub commented Dec 14, 2023

I had the same issue using this, self.version = F("version") + 1.
Now if I use the below code, I am getting this error django.core.serializers.base.DeserializationError: ['“F(version) + Value(1)” value must be an integer.']

        with transaction.atomic(), reversion.create_revision():
            self.save()
            reversion.set_user(user)

but if I use this code, the revision is working fine, but I think this is a little inefficient,

       self.save()
       with transaction.atomic(), reversion.create_revision():
           self.refresh_from_db()
           self.save()
           reversion.set_user(user)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants