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

Type change in custom type does not actually change the type in CT #40

Closed
davidweterings opened this issue Nov 21, 2018 · 3 comments
Closed
Labels
bug Something isn't working resource_type resource_type

Comments

@davidweterings
Copy link
Member

davidweterings commented Nov 21, 2018

Changing a custom type value from f.e. Enum -> String says it succeeded but doesn't actually change it in CommerceTools (formatting here is borked...):

Before

resource "commercetools_type" "custom-order-fields" {
  key = "custom-order-fields"
  name = {
    en = "Custom order fields"
  }

  description = {
    en = "Custom order fields"
  }

  resource_type_ids = ["order"]
  field {
    name = "shipwireServiceLevelCode"

    label = {
      en = "Shipwire service level code"
      nl = "Shipwire service level code"
    }

    type {
      name = "Enum"
      values {
        foo = "bar"
      }
    }
  }

After

resource "commercetools_type" "custom-order-fields" {
  key = "custom-order-fields"
  name = {
    en = "Custom order fields"
  }

  description = {
    en = "Custom order fields"
  }

  resource_type_ids = ["order"]
  field {
    name = "shipwireServiceLevelCode"

    label = {
      en = "Shipwire service level code"
      nl = "Shipwire service level code"
    }

    type {
      name = "String"
    }
  }

TF output:

  ~ commercetools_type.custom-order-fields
      field.1.type.0.name:                           "Enum" => "String"
      field.1.type.0.values.%:                       "7" => "0"
      field.1.type.0.values.economy_international:   "E-INTL" => ""
      field.1.type.0.values.ground_domestic:         "GD" => ""
      field.1.type.0.values.one_day_domestic:        "1D" => ""
      field.1.type.0.values.plus_international:      "PL-INTL" => ""
      field.1.type.0.values.premium_international:   "PM-INTL" => ""
      field.1.type.0.values.standard_international:  "INTL" => ""
      field.1.type.0.values.two_day_domestic:        "2D" => ""
@mvantellingen mvantellingen added the bug Something isn't working label Jul 22, 2019
@StarpTech
Copy link

StarpTech commented Nov 4, 2019

This is no bug. According to the code, this is just not implemented. We only respect enum changes not type changes from X to Y. In your example, the actions are zero.

if enumType, ok := newFieldType.(commercetools.CustomFieldEnumType); ok {
oldEnumV := oldFieldType["values"].(map[string]interface{})
for i, enumValue := range enumType.Values {
if _, ok := oldEnumV[enumValue.Key]; !ok {
// Key does not appear in old enum values, so we'll add it
actions = append(
actions,
commercetools.TypeAddEnumValueAction{
FieldName: name,
Value: &enumType.Values[i],
})
}
}
// Action: changeEnumValueOrder
// TODO: Change the order of EnumValues: https://docs.commercetools.com/http-api-projects-types.html#change-the-order-of-fielddefinitions
} else if enumType, ok := newFieldType.(commercetools.CustomFieldLocalizedEnumType); ok {
oldEnumV := oldFieldType["localized_value"].([]interface{})
oldEnumKeys := make(map[string]map[string]interface{}, len(oldEnumV))
for _, value := range oldEnumV {
v := value.(map[string]interface{})
oldEnumKeys[v["key"].(string)] = v
}
for i, enumValue := range enumType.Values {
if _, ok := oldEnumKeys[enumValue.Key]; !ok {
// Key does not appear in old enum values, so we'll add it
actions = append(
actions,
commercetools.TypeAddLocalizedEnumValueAction{
FieldName: name,
Value: &enumType.Values[i],
})
}
}

Besides that, it's important no note that in commercetools, custom field definitions(identified by its name) are "singletons". As soon as a field definition is used by more than one custom type it's not possible to change the type of the field without changing the name.

Therefore in that scenario, it's always required to create a new field if we want to update the type.

This could be tricky to check. WDYT?

@mvantellingen mvantellingen added the resource_type resource_type label Jul 5, 2022
@mvantellingen
Copy link
Member

Commercetools doesn't support changing the type of a field. I think we now show an error in terraform that you need to delete the field and add it again. We need to check this

@mvantellingen
Copy link
Member

Just checked; we are raising an error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resource_type resource_type
Projects
None yet
Development

No branches or pull requests

3 participants