Django admin request got values for both 'fields' and 'body' error when trying to save entry with CloudinaryField attribute

huangapple go评论54阅读模式
英文:

Django admin request got values for both 'fields' and 'body' error when trying to save entry with CloudinaryField attribute

问题

I am working on a Django project and suddenly I have found that when the user tries to save a new entry with an image there is an exception:
"request got values for both 'fields' and 'body', can only specify one."

I am using the Django Admin in conjunction with the Cloudinary library where I am using the CloudinaryField on the specific table.

In addition, I have a one-to-many relationship between MainEntity and Picture. The Picture model holds a CloudinaryField.

When I am trying to use traceback to get a detailed error, I am getting another error related to the database:

"An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block."

The problem arises when I am calling the save method manually after the overridden that I have made in the Picture model:

def save(self, *args, **kwargs):
    if not self.order:
        self.order = self.mainEntity.number_of_pictures() + 1
    try:
        super(Picture, self).save(*args, **kwargs)
    except BaseException:
        traceback.print_exc()

What I have found is that the exception happens in request_encode_body method that you can find in this URL.

Although, I cannot understand why this is happening and what causes this issue!

Thank you!

What I have tried in detail

I have tried to downgrade Cloudinary and Django dependencies to the versions that I was using from the beginning of the project.

Checked the Cloudinary credentials.

Found the documentation of the method that throws the exception and tried to investigate more.

英文:

I am working on a Django project and suddenly I have found that when user tries to save a new entry with an image there is an exception:
request got values for both 'fields' and 'body', can only specify one

I am using the Django Admin in conjunction with the Cloudinary library where I am using the CloudinaryField on the specific table.

In addition, I have one to many relationship between MainEntity and Picture. The Picture model holds a CloudinaryField.

When I am trying to use traceback to get a detailed error I am getting another error related with database:

An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.

The problem arises when I am calling the save method manually after the overridden that I have made in Picture model:

    def save(self, *args, **kwargs):
        if not self.order:
            self.order = self.mainEntity.number_of_pictures() + 1
        try:
            super(Picture, self).save(*args, **kwargs)
        except BaseException:
            traceback.print_exc()

What I have found is that the exception happens in request_encode_body method that you can find in this url.

Although, I cannot understand why this is happening and what causes this issue!

Thank you!

What I have tried in detail

I have tried to downgrade Cloudinary and Django dependencies to the versions that I was using from the beginning of the project.

Checked the Cloudinary credentials.

Found the documentation of the method that throws the exception and try to investigate more.

答案1

得分: 1

我曾经遇到和你一样的问题。我使用的是 Cloudinary 的 1.23.0 版本。在升级到 1.33.0(最新版本)之后,问题得到解决。尝试升级你的 Cloudinary 依赖。

英文:

I'had the exact same problem as you.
I was using the 1.23.0 version of Cloudinary.
After upgrading it to the 1.33.0 (last current version) it works again.
Try upgrading your Cloudinary dependency.

huangapple
  • 本文由 发表于 2023年6月27日 18:04:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76563762.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定