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

language property exported with str and dict values #121

Open
zopyx opened this issue Apr 18, 2022 · 3 comments
Open

language property exported with str and dict values #121

zopyx opened this issue Apr 18, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@zopyx
Copy link
Contributor

zopyx commented Apr 18, 2022

I have a Plone 5.2 AT site that exports most of the content with

 "language": "" 

and some content items as

    "language": {
        "title": "Deutsch",
        "token": "de"
    },

This leads to import errors such as

2022-04-18 14:24:26,230 WARNING [collective.exportimport.import_content:352][waitress-2] cannot deserialize https://nohost/eteaching/projekt/rechte/hochschulmitglieder-als-urheber: BadRequest([{'message': 'Constraint not satisfied', 'field': 'language', 'error': 'ValidationError'}])
@zopyx zopyx added the bug Something isn't working label Apr 18, 2022
@mauritsvanrees
Copy link
Member

Is 'de' in the allowed languages of the new site?

@petschki
Copy link
Member

In our current project, we have item language exported from Plone 4.3.20 as "language": "en" and if the target Plone Site doesn't allow en we get the deserialization error. otherwise it gets imported correctly.

@mauritsvanrees
Copy link
Member

I have this in custom code, which fixes the problem for my case (export example content from English site, import it in Spanish site):

class CustomImportContent(ImportContent):
    def global_dict_hook(self, item):
        # When we export English content and import it in the Spanish site,
        # we must change the langue to Spanish, otherwise you get an error:
        # zExceptions.BadRequest: [{'message': 'Constraint not satisfied',
        # 'field': 'language', 'error': 'ValidationError'}]
        # BTW, the value is for example:
        # {'title': 'Nederlands', 'token': 'nl'}
        # Hey, wouldn't the easiest be to drop the key?  Seems to work fine.
        # Alternatively, use self.context.Language(), so a language is really set.
        # This might be better for multilingual sites.
        language = item.pop("language", None)
        if language is not None:
            logger.info("Popped language %s from item.", language)
        return item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants