django-cms / djangocms-transfer

django CMS Transfer allows you to export and import plugins.
https://www.django-cms.org
Other
19 stars 19 forks source link

Import Error: File is not valid #16

Open sharkovsky opened 3 years ago

sharkovsky commented 3 years ago

Hello,

I am getting a File is not valid error when I try to import some plugins.

By inspecting with a debugger, I have pinned down the issue to the presence of the plugin_type field within the data dictionary of a plugin. To be more clear, here is a json example of a problematic plugin:

[{
    "pk": 155,
    "creation_date": "2020-11-03T17:29:48.460Z",
    "position": 0,
    "plugin_type": "BannerTopPlugin",
    "parent_id": null,
    "data": {
        "path": "002J",
        "depth": 1,
        "numchild": 0,
        "placeholder": 13,
        "parent": null,
        "position": 0,
        "language": "it",
        "plugin_type": "BannerTopPlugin",
        "creation_date": "2020-11-03T17:29:48.460Z",
        "changed_date": "2020-11-03T17:29:48.463Z"
}}]

The existence of the plugin_type field within the data dictionary confuses the _object_version_data_hook function, which tries to instantiate an ArchivedPlugin, but fails because of the existence of unknown parameters such as path. Indeed, I could implement a simple fix by patching the _object_version_data_hook to return right away the data dictionary untouched if it doesn't contain the pk key.

Obviously this fix is not sustainable, and it would be better to understand why the plugin_type key is duplicated in the first place. An important hint that I discovered is that this problem seems to only happen with plugins that don't have an associated model in the database.

I am using Django 2.2, django-cms 3.7.4 and djangocms-transfer 1.0.0

Thank you!

srinathganesh commented 2 years ago

I faced a similar problem and doing the folliwing manually does solve the error

Remove plugin_type from data

GinnWG commented 2 years ago

I met the same problem