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

Importing (JSON2) fails with "Cannot read properties of null (reading 'localizations')" #74

Closed
akarelinsbs opened this issue Oct 26, 2022 · 10 comments

Comments

@akarelinsbs
Copy link

I have a localised instance v4.4.5 with the latest version of Import/Export plugin.

The instance has two languages enabled (Italian & English).

When I try to import the following JSON2 entity

{ "version": 2, "data": { "api::allergen.allergen": { "1": { "id": 1, "name": "Glutine", "description": "Cereali, grano, segale, orzo, avena, farro, kamut, inclusi ibridati e derivati." } } } }

it fails with

"Cannot read properties of null (reading 'localizations')"

error.

@mmange
Copy link

mmange commented Oct 26, 2022

I have encountered the same error when localization: [] in the json.

Once I added localization for 1 entry, the import went but, that's not feasible for all entries.

In the following example I am getting an error even with localizations present for 2 entries.

	"version": 2,
	"data": {
		"api::page.page": {
			"2": {
				"id": 2,
				"title": "home",
				"publish_at": null,
				"ready": null,
				"slug": "en-us",
				"createdAt": "2022-10-26T23:09:38.798Z",
				"updatedAt": "2022-10-26T23:14:36.927Z",
				"publishedAt": null,
				"locale": "en",
				"blocks": [],
				"seo": null,
				"parent": null,
				"redirect": null,
				"createdBy": null,
				"updatedBy": null,
				"localizations": [
					3
				]
			},
			"3": {
				"id": 3,
				"title": "home-es",
				"publish_at": null,
				"ready": null,
				"slug": "es-es",
				"createdAt": "2022-10-26T23:09:44.594Z",
				"updatedAt": "2022-10-26T23:16:24.292Z",
				"publishedAt": null,
				"locale": "es",
				"blocks": [],
				"seo": null,
				"parent": null,
				"redirect": null,
				"createdBy": null,
				"updatedBy": null,
				"localizations": [
					2
				]
			},
			"4": {
				"id": 4,
				"title": "child1",
				"publish_at": null,
				"ready": null,
				"slug": "en-us~child1",
				"createdAt": "2022-10-26T23:14:13.861Z",
				"updatedAt": "2022-10-26T23:16:00.377Z",
				"publishedAt": null,
				"locale": "en",
				"blocks": [],
				"seo": null,
				"parent": 2,
				"redirect": null,
				"createdBy": null,
				"updatedBy": null,
				"localizations": [
					5
				]
			}
			
		},
		"general.text": {},
		"general.image": {},
		"shared.redirect": {},
		"shared.seo": {},
		"plugin::upload.file": {},
		"general.link": {},
		"shared.meta-social": {},
		"plugin::upload.folder": {}
	}
}

@Baboo7
Copy link
Owner

Baboo7 commented Oct 27, 2022

Hey @mmange @akarelinsbs this is the issue I am currently working on. I made significant progress and I will have a fix by end of next week

Feel free to join the discord of the community (see readme) to have the latest updates

@Baboo7
Copy link
Owner

Baboo7 commented Oct 27, 2022

I published version 1.17.0 that focuses on exporting/importing single types with json v2 format

@JWesorick
Copy link

I am using 1.18.0 and have a very similar error when importing with v2:

Cannot read properties of undefined (reading 'attributes')

This is just doing a "Quick Actions" export and then trying to import it.

@Baboo7
Copy link
Owner

Baboo7 commented Nov 13, 2022

Can you share the schema of the collection that triggers the issue?

@JWesorick
Copy link

JWesorick commented Nov 14, 2022

Here is my import json

{
  "version": 2,
  "data": {
    "api::playlist.playlist": {
      "139": {
        "id": 139,
        "title": "Hey",
        "slug": "abc-123",
        "createdAt": "2022-08-15T03:40:47.967Z",
        "updatedAt": "2022-11-14T02:44:49.463Z",
        "locale": "en",
        "members": [2520],
        "createdBy": null,
        "updatedBy": null
      },
      "general.media-element": {
        "2520": {
          "id": 2520,
          "mediaRecord": 1379
        }
      },
      "api::media-record.media-record": {
        "1379": {
          "id": 1379,
          "title": "yo",
          "type": "audio",
          "videoSource": null,
          "slug": "yo-1",
          "createdAt": "2022-08-15T03:40:47.876Z",
          "updatedAt": "2022-11-14T02:25:35.512Z",
          "locale": "en",,
          "audioSources": [68],
          "createdBy": null,
          "updatedBy": null
        }
      },
      "plugin::upload.file": {
        "68": {
          "id": 68,
          "name": "01_01.mp3",
          "alternativeText": "01_01.mp3",
          "caption": "01_01.mp3",
          "hash": "01_01_c9933681c8",
          "ext": ".mp3",
          "mime": "audio/mpeg",
          "url": "https://my-aws.amazonaws.com/01_01_c9933681c8.mp3",
          "createdAt": "2022-08-24T07:15:07.707Z",
          "updatedAt": "2022-08-24T07:15:07.707Z",
          "createdBy": 1,
          "updatedBy": 1
        }
      }
    }
  }
}

@Baboo7
Copy link
Owner

Baboo7 commented Nov 14, 2022

@JWesorick the issue I see is that all collections are part of the data of the collection api::playlist.playlist

@JWesorick
Copy link

🤦🏻 Yea that was it. Correctly formatting the JSON makes it work.

@Baboo7 Baboo7 closed this as completed Nov 18, 2022
@m-torin
Copy link

m-torin commented Dec 7, 2022

@JWesorick what did you change to make the JSON formatted correctly? Your snippet passes validation.

@Baboo7
Copy link
Owner

Baboo7 commented Dec 8, 2022

@m-torin you can find an example in the doc in the Importing Data section.

Here the issue was the collections were nested in another collection instead of being in the object data

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

5 participants