Open MrAlecJohnson opened 4 years ago
Hi all, I have a similar issue. I went into the code and tried to debug it, here's what I've found.
contentful-management-2.12.1/lib/contentful/management/field.rb:90
It crashes when validation
is a hash since it does not have properties_to_hash
NoMethodError: undefined method 'properties_to_hash' for {}:Hash
I tried adding a check for hashes, but after trying, the API actually ignored creating a new field
def validations_to_hash(validations)
validations.each_with_object([]) do |validation, results|
if validation.is_a? Hash
results << validation
else
results << validation.properties_to_hash
end
end
end
Hi @MrAlecJohnson and @vitscurtu,
I am taking a look at this issue, and trying to reproduce it. Can you please confirm if you are still facing the issue?
Cheers, Bhushan
Hi @rubydog - thanks for the reply. I've moved on from that job so I'm afraid I don't know how things have changed since this came up. I've pointed folks still working there in the direction of this issue, so hopefully someone will be in touch if it is still causing problems.
@rubydog,
I'm still able to reproduce the issue. Let me know if you need more details/log data.
@vitscurtu.
Can you please share with me detailed steps to reproduce this issue?
Summary If I have a content type, I can normally use the API to add fields to it.
If that content type contains a rich text field with validations, I can no longer use the API to add fields to it. I've found a workaround, but it destroys some validations.
Details I create a content type called
test_type
, either through the web app or through the API. That content type does not contain a rich text field. I retrieve the content type through the api with:I can now use the API to add a field to that content type, using either of the documented approaches:
or
This is fine. But if test_type contains a rich text field, I get an error when trying to save the new field back to the content type:
When I break things down step by step, this goes wrong at the
fields.create
stage, hitting an error with the rich text field's validations:Before I run
fields.create
the rich text field's validations are:This leaves out a lot of the rich text field validations, such as 'accept only specified entry type'. I assume they in some way account for the second item in the validations array - the one that seems to be blank in the API response.
After I run
fields.create
the validation objects change to hashes:Partial workaround The problem in my example above seems to be connected to the second item in the validations array - the one that becomes an empty hash during the
fields.create
process.So I can avoid these errors by deleting the last item from the rich text field's validations array before I run
fields.create
. This lets me create and save the new field, no matter what combination of validations I have on my rich text field.However, it can also delete some validations from the rich text field, so it isn't an ideal workaround! It lets me keep 'required field' (which isn't part of the validations array) and 'limit character count', but if I have any other validations (such as 'accept only specified entry type'), they're deleted. These validation types are the ones that aren't returned by the API, so I'm guessing this is connected to the problem.
An exception This error still happens if the rich text field has no validations. However, it doesn't happen if, when I create the rich text field, I press 'create' without clicking on 'create and configure' or visiting the rich text field's settings menu.
System and environment details I'm running this as a little local testing script in Ruby 2.6.3, using just the Contentful management gem.