ConstraintNotSatisfied: ('ab', 'language') when modifying a content type TTW

I have a content type made a year ago and if I try to edit it TTW (after i minor upgrade of the Phone 5 site), I get

Traceback (innermost last):
Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module plone.z3cform.layout, line 63, in __call__
Module plone.z3cform.layout, line 47, in update
Module plone.z3cform.fieldsets.extensible, line 65, in update
Module plone.z3cform.patch, line 30, in GroupForm_update
Module z3c.form.group, line 141, in update
Module z3c.form.group, line 52, in update
Module z3c.form.group, line 48, in updateWidgets
Module z3c.form.field, line 277, in update
Module z3c.form.browser.select, line 51, in update
Module z3c.form.browser.widget, line 171, in update
Module z3c.form.widget, line 234, in update
Module Products.CMFPlone.patches.z3c_form, line 47, in _wrapped
Module z3c.form.widget, line 115, in update
 Module zope.schema._bootstrapfields, line 78, in __get__
Module zope.schema._bootstrapfields, line 183, in validate
Module zope.schema._field, line 338, in _validate
ConstraintNotSatisfied: ('ab', 'language')

when you edit your content, what's the value displayed in the language (DublinCore) field ?

Maybe I was a bit unclear (it was midnight :slight_smile: )
The error happens when I edit the Dexterity Content type.

The language of content (of all content types) shows as 'Norwegian'.

I discovered that when making a new content type TTW the same things happens, so maybe there is something with an an upgrades step…

yes but when you edit a content type a language is displayed in the language field. It's not very easy to see it as it is disabled but there is a default.
I noticed that it's not the default language site for me.

That part looks OK.

But if I do:

  1. Add a new Dexterity Content type
  2. Try to add a new field to it

I get the same error.

under debug, what is returning

 app.<plone site>.Language() ?

It shows:
u'no'

Do you think 'somehow it is looking for 'language ab', as in 'Abkhazian" :

(maybe Voldermort is around :slight_smile: )

EDIT: Adding ALL available languages in the control panel seems to work… something interesting happens every day …

39

Abkhazian is well and truly in the language field...
This interesting sequence means 'language' in Abkhazian according to the highest Internet authorities. You can see it in the Plone avaiilable languages list with other Cyrillic languages. It's a bit difficult for people not coming from this part of the world to recognize it as 'ab'.
It was my impression that this part comes from the language setting for the site that's why I was asking for the return of Language().

Actually, I think it is the other way around (please correct me if I am wrong):

The 'Dublin Core behavior for some reason has 'ab' as language, and this language was not installed on the site.
Where it gets its settings from, only 'He-who-must-not-be-named' knows :vampire:

What happens if you look at the XML field model... does it show a default value for the language field?

I dont think you can see that in the field model, since it comes from a behavior.

If you clone the content type does that default language value get copied?

Could you recreate the content type from scratch TTW (after renaming the existing one) so that it doesn't have that default language value?

Every approach gets ab as language. So I think the behavior gets it from somewhere (or probably the place it gets it from is not set)

I am not sure of what is the exact meaning of what you say ? :slight_smile:
What I have observed from the code and some tests.

in the TTW Dexterity configuration, the langage is handled so (plone/app/dexterity/behaviors/metadata.py):

    language = schema.Choice(
        title=_(u'label_language', default=u'Language'),
        vocabulary='plone.app.vocabularies.SupportedContentLanguages',
        required=False,
        missing_value='',
        defaultFactory=default_language,

with default_language being:

@provider(IContextAwareDefaultFactory)
def default_language(context):
    # If we are adding a new object, context will be the folderish object where
    # this new content is being added
    language = None

    if context is not None and not IPloneSiteRoot.providedBy(context):
        language = context.Language()
        if not language:
            # If we are here, it means we were editing an object that didn't
            # have its language set or that the container where we were adding
            # the new content didn't have a language set. So we check its
            # parent, unless we are at site's root, in which case we get site's
            # default language
            if not IPloneSiteRoot.providedBy(context.aq_parent):
                language = context.aq_parent.Language()

    if not language:
        # Finally, if we still don't have a language, then just use site's
        # default
        pl = getToolByName(getSite(), 'portal_languages')
        language = pl.getDefaultLanguage()

    return language

you can guess the reasoning of the programmer from the very detailed comments.
The programmer knows that at the site root is lurking a monster, the .Language() provided by Zope and set (I think) when installing Plone. This value is never changed by the Plone UI. So he is using the context, and the parent's context unless it is the site root. And if all else fails, he use getDefaultLanguage, in other words the value taken from the registry, the one that is set in the Plone control panel.
I did not test but I am sure that it works fine in normal cases.

Unfortunately.

when editing a Dexterity Control Type TTW, this is not working.

In this case, context.Language() goes straight to the site. I could see that self in the DublinCore.py file was referring to the site, that is a language that was NOT my current langage.

I tried then to 'fix' a test instance.
In debug mode, I set
plone.language = 'ab'
Then plone.Language() returns 'ab'. A commit, a restart and a test: same problem as yours. If I add Abkhazian to the selected languages, my default language for a new Dexterity Content has turned to бызшәа.
this 'feature' works on 5.08 and 5.1 pending.

I have this problem, at least I think so. Plone 5.1.5 with, as it happens, English (United Kingdom) set as the default language somewhere in the Zope/Plone outer darkness. In the Plone UI Site Setup > Language the Site language is set as English. If I remove English (United Kingdom) from the list of available languages I can no longer use Dexterity TTW because it complains about unavailable language. From the IDublinCore behavior: language I see a greyed-out 'English (United Kingdom)' setting.
From the above it looks like I need to change plone.language to whatever I want it to be (in this case plain 'en'). But how? Can I do it in my site package configure.zcml or buildout?

I dont think you can not remove it if you use the Dexterity control.
Add your (new) language as default and on top of the list.

I have found no other workaround for this problem

Thanks Espen. That is not great news. I'll just hide it then:
.language-en-gb {
display: none;
}

For you info:

You can do the following

  1. enable the language
  2. Go to the dexterity control panel and 'do your stuff'.
  3. Disable the language

Then repeat next time you need to do stuff in the control panel