-
Couldn't load subscription status.
- Fork 16
Description
Steps to reproduce
-
Create content model (e.g. "foo") with field
pg_rating(multiple words in snake_case) in Contentful. -
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.