Skip to content

Create entry requires field name in camelCase #67

@Toreno96

Description

@Toreno96

Steps to reproduce

  1. Create content model (e.g. "foo") with field pg_rating (multiple words in snake_case) in Contentful.

  2. Try to create a new entry:

    new_entry = environment.entries().create(
        'new_entry_id',
        {"content_type_id": "foo", "fields": {"pg_rating": {"en-US": "value"}}}
    )

Encountered behavior

An error is raised:

...
contentful_management.errors.UnprocessableEntityError: HTTP status code: 422
Message: No field with id "pg_rating" found.
Details:
        * Name: unknown - Path: '['fields', 'pg_rating']'

Expected behavior

Entry is created, the current value of its pg_rating field is value.

Workaround

When creating a new entry, field name has to be written in camelCase:

new_entry = environment.entries().create(
     'new_entry_id',
     {"content_type_id": "foo", "fields": {"pgRating": {"en-US": "value"}}}
)

That's the underlying issue with API, not SDK, as I tried to make direct request to the API using httpie and it also returns an error:

{
    "details": {
        "errors": [
            {
                "name": "unknown",
                "path": [
                    "fields",
                    "pg_rating"
                ]
            }
        ]
    },
    "message": "No field with id \"pg_rating\" found.",
    "requestId": "f72e32ec9560123245887252d1c9ee13",
    "sys": {
        "id": "UnknownField",
        "type": "Error"
    }
}

Suggested solutions

Implement workaround in SDK

If it's easier to fix that here than in API.

Especially that the issue introduces inconsistency; during update it is actually not possible to use camelCase, snake_case is required there:

(Pdb) entry.pg_rating
'value'
(Pdb) entry.pgRating
*** AttributeError: 'Entry' object has no attribute 'pgRating'

Document the issue

I found no info about how multiword field names are handled, neither in docs of SDK, nor in docs of API.

There's no example if user should use snake_case or camelCase, or what.

If it's non-trivial to implement a workaround in SDK or fix in API, then documenting it explicitly would be at least something.

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