Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Field#properties_to_hash method #192

Merged
merged 1 commit into from
Apr 23, 2019

Conversation

HQ063
Copy link
Contributor

@HQ063 HQ063 commented Apr 22, 2019

On the Field class, when converting the properties to a hash for sending the API request, the method is not avoiding empty values (it does already avoid them when serializing validators).

These cause some requests to fail when trying to creating new content models using an existing (from another model) complex (array or referenced) field as the source.

This small change fixes the issue and allows for complex content model migrations or duplication.

Before:

#source_environment = ...
#target_environment = ...
pry(main)> content_model = source_environment.content_types.find('complex_sample_model')
pry(main)> new_content_type = target_environment.content_types.create(id: content_model.id, name: content_model.name, fields: content_model.fields)
=> Contentful::Management::UnprocessableEntity: HTTP status code: 422 Unprocessable Entity
Message: Validation error
Details: 
	* Name: unexpected - Path: '["fields", 1, "items", "id"]' - Value: ''
	* Name: unexpected - Path: '["fields", 1, "items", "items"]' - Value: ''
	* Name: unexpected - Path: '["fields", 1, "items", "name"]' - Value: ''
	* Name: unexpected - Path: '["fields", 1, "items", "omitted"]' - Value: ''
	* Name: unexpected - Path: '["fields", 1, "items", "required"]' - Value: ''
	* Name: unexpected - Path: '["fields", 1, "items", "disabled"]' - Value: ''
	* Name: unexpected - Path: '["fields", 1, "items", "localized"]' - Value: ''
Request ID: 4ba35367324d77bf9610217f1f2eb77c
from /Users/hq063/.rvm/gems/ruby-2.5.1@juulio/gems/contentful-management-2.6.0/lib/contentful/management/client.rb:390:in `execute_request'

With this fix:

#source_environment = ...
#target_environment = ...
pry(main)> content_model = source_environment.content_types.find('complex_sample_model')
pry(main)> new_content_type = target_environment.content_types.create(id: content_model.id, name: content_model.name, fields: content_model.fields)
#<Contentful::Management::ContentType: @properties=....>

@HQ063 HQ063 force-pushed the fix-field-properties-serializing branch from dea5b7a to d6cfbc8 Compare April 23, 2019 04:25
@dlitvakb
Copy link
Contributor

Gracias!

Merging

@dlitvakb dlitvakb merged commit f9adfe9 into contentful:master Apr 23, 2019
@dlitvakb
Copy link
Contributor

Released in version 2.8.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants