Skip to content

YAMLException when defining an optional object with optional image fields #253

Closed
@MadsMadsDk

Description

@MadsMadsDk

- Do you want to request a feature or report a bug?
Bug

- What is the current behavior?
NetlifyCMS throws a YAMLException: "unacceptable kind of an object to dump [object Undefined]. I suspect it is caused by defining an object, that contains a bunch of optional images (a relevant usecase would be, like in this case, to implement a responsive image strategy), and not referencing any images as they are optional.

- If the current behavior is a bug, please provide the steps to reproduce.

  1. Add this to the config.yml:
- name: "landing_page"
    label: "Landing page"
    folder: "_pages/landing-pages"
    sort: "date:desc"
    create: true
    fields: # The fields each document in this collection have
      - {label: "Layout", name: "layout", widget: "string", default: "landing-page"}
      - {label: "Page title", name: "title", widget: "string"}
      - label: "Hero"
        name: "hero"
        widget: "object"
        optional: true
        fields:
          - {label: "Headline", name: "headline", widget: "text", tagname: "h2", optional: true}
          - {label: "Short intro", name: "lead", widget: "text", optional: true}
          - {label: "Hero layout", name: "hero_layout", widget: "string", optional: true}
      - name: "sections"
        label: "sections"
        widget: list
        optional: true
        fields:
          - {label: "Section layout", name: "section_layout", widget: "string", default: "section"}
          - {label: "Section content", name: "section_content", widget: "markdown", optional: true}
          - {label: "Section content position", name: "section_content_position", widget: "string", optional: true}
          - {label: "Section content image", name: "section_content_image", widget: "image", optional: true}
          - name: "section_background_images"
            label: "Section background images"
            widget: "object"
            optional: true
            fields:
              - {label: "Mobile (600w)", name: "section_bg_600w", widget: "image", optional: true}
              - {label: "Tablet (1024w)", name: "section_bg_1024w", widget: "image", optional: true}
              - {label: "Desktop (1400w)", name: "section_bg_1400w", widget: "image", optional: true}
              - {label: "Full (1920w)", name: "section_bg_1920w", widget: "image", optional: true}
          - {label: "Image alt", name: "section_bg_alt", widget: "string", optional: true}
          - {label: "Show on mobile?", name: "section_bg_mobile_show", widget: "string", optional: true}
          - {label: "Background class", name: "section_bg_class", widget: "string", optional: true}
    meta: # Meta data fields. Just like fields, but without any preview element
      - {label: "Publish Date", name: "date", widget: "datetime", format: "YYYY-MM-DD hh:mm:ss"}
      - {label: "Permalink", name: "permalink", widget: "string"}
      - {label: "Language", name: "lang", widget: "string"}
      - {label: "Meta title", name: "meta_title", widget: "string"}
      - {label: "Meta description", name: "meta_description", widget: "text"}
      - name: sitemap
        label: "Sitemap settings"
        optional: true
        widget: object
        fields:
          - {label: "Exclude from sitemap?", name: "exclude", widget: "string", default: "no", optional: true}
          - {label: "Sitemap priority", name: "priority", widget: "string", default: "0.5", optional: true}
  1. Attempt to create a new "Landing Page", but without filling in any of the optional fields (only "Section layout" is mandatory).
  2. Try to save the document. It will result in an endless spinner, and said YAMLException.

- What is the expected behavior?
That NetlifyCMS produces a markdown file that looks like this:

---
layout: landing-page
title: Landing Page Title
hero:
  headline: ""
  lead: ""
  hero_layout: ""
sections:
  - section_layout: "-some-layout-string"
    section_content: ""
    section_content_position: ""
    section_content_image: null
    section_background_images:
      section_bg_600w: null
      section_bg_1024w: null
      section_bg_1400w: null
      section_bg_1920w: null
    section_bg_alt: ""
    section_bg_mobile_show: ""
    section_bg_class: ""
---

- Please mention your node.js, and operating system version.
Node v7.2.0
OS: macOS Sierra 10.12.3

Also using Netlify-git-api, and using the Netlify version shipped via CDN.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions