Skip to content

Fetching content types of an environment results in MessageValidation error #178

@bonwon

Description

@bonwon

Description

When a content type contains an array or integer field with a custom error message then function getContentTypes() fails with error message "Fatal error: Uncaught Error: Class "\Contentful\Management\Mapper\ContentType\Validation\MessageValidation" not found in /myproject/vendor/contentful/contentful-management/src/ResourceBuilder.php:31"

Impact

Because of the issue our maintenance/utility PHP scripts cannot work on environments that have content types including custom error messages as part of the field validation.

Replication

    $client = new \Contentful\Management\Client('<content_management_api_key>');`
    $environment = $client->getEnvironmentProxy('<space_id>', '<environment_id>');
    $contentTypes = $environment->getContentTypes();
  • execute test using php test.php

Error

PHP Fatal error: Uncaught Error: Class "\Contentful\Management\Mapper\ContentType\Validation\MessageValidation" not found in /myproject/vendor/contentful/contentful-management/src/ResourceBuilder.php:31
Stack trace:
#0 /myproject/vendor/contentful/core/src/ResourceBuilder/BaseResourceBuilder.php(74): Contentful\Management\ResourceBuilder->createMapper('\Contentful\Man...')
#1 /myproject/vendor/contentful/contentful-management/src/Mapper/ContentType/Field/BaseField.php(68): Contentful\Core\ResourceBuilder\BaseResourceBuilder->getMapper('\Contentful\Man...')
#2 [internal function]: Contentful\Management\Mapper\ContentType\Field\BaseField->mapValidation(Array)
#3 /myproject/vendor/contentful/contentful-management/src/Mapper/ContentType/Field/BaseField.php(56): array_map(Array, Array)
#4 /myproject/vendor/contentful/contentful-management/src/Mapper/ContentType.php(47): Contentful\Management\Mapper\ContentType\Field\BaseField->map(NULL, Array)
#5 [internal function]: Contentful\Management\Mapper\ContentType->mapField(Array)
#6 /myproject/vendor/contentful/contentful-management/src/Mapper/ContentType.php(34): array_map(Array, Array)
#7 /myproject/vendor/contentful/core/src/ResourceBuilder/BaseResourceBuilder.php(58): Contentful\Management\Mapper\ContentType->map(NULL, Array)
#8 /myproject/vendor/contentful/contentful-management/src/Mapper/ResourceArray.php(28): Contentful\Core\ResourceBuilder\BaseResourceBuilder->build(Array)
#9 [internal function]: Contentful\Management\Mapper\ResourceArray->Contentful\Management\Mapper{closure}(Array)
#10 /myproject/vendor/contentful/contentful-management/src/Mapper/ResourceArray.php(27): array_map(Object(Closure), Array)
#11 /myproject/vendor/contentful/core/src/ResourceBuilder/BaseResourceBuilder.php(58): Contentful\Management\Mapper\ResourceArray->map(NULL, Array)
#12 /myproject/vendor/contentful/contentful-management/src/Client.php(155): Contentful\Core\ResourceBuilder\BaseResourceBuilder->build(Array, NULL)
#13 /myproject/vendor/contentful/contentful-management/src/Client.php(253): Contentful\Management\Client->request('GET', '/spaces/a1b2c3...', Array)
#14 /myproject/vendor/contentful/contentful-management/src/ClientExtension/Space/Environment/ContentTypeExtension.php(53): Contentful\Management\Client->fetchResource('Contentful\Mana...', Array, NULL)
#15 /myproject/error-case.php(15): Contentful\Management\Client->getContentTypes('a1b2c3', 'development')
#16 {main}
thrown in /myproject/vendor/contentful/contentful-management/src/ResourceBuilder.php on line 31

Note(s)

  • issue is in the contentful-management.php project as the CMA responds without errors, and the Python client library has no issue parsing the CMA response.
    • CMA request: curl -v -H "Authorization: Bearer CFPAT-XXXXX" "https://api.contentful.com/spaces/a1b2c3d4e5/environments/development/content_types"
    • test.py:
    import contentful_management
    client = contentful_management.Client('CFPAT-XXXXX')
    content_types = client.content_types('a1b2c3d4e5 'development').all()
  • example field definition that breaks the SDK
{
  "id": "maxItems",
  "name": "Max Items",
  "type": "Integer",
  "localized": false,
  "required": false,
  "validations": [
    {
      "message": "Must be between 1 and 7",
      "range": {
        "max": 7,
        "min": 1
      }
    }
  ],
  "disabled": false,
  "omitted": false
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions