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

default values in complex datatypes are not overwritten with empty binary #6

Open
grundrauschen opened this issue Nov 17, 2015 · 4 comments

Comments

@grundrauschen
Copy link

default values in complex datatypes are not overwritten with empty binary

I assume I found a bug in how this version of conform handles default values of binaries in complex datatypes:

The error occurred with the following example schema

[
  mappings: [
      "test.routes.*": [
      to: "app.routes",
      datatype: [:complex],
      default: []
    ],
    "test.routes.*.foo": [
      doc: "foooo",
      to: "app.routes",
      datatype: :binary,
      default: "bar"
    ],
    "test.routes.*.ham": [
      doc: "ham",
      to: "app.routes",
      datatype: :binary,
      default: "egg"
    ],
    "test.test": [
      doc: "test",
      to: "app.test",
      datatype: :binary,
      default: "peng"
    ]
  ],
  translations: [
      "app.routes.*": fn _h, {key, value_map}, acc ->
      acc ++ [{key, [foo: value_map[:foo],
                     ham: value_map[:ham]]}]
    end
  ]
]

using the following app.con

test.routes.route1.foo = "baaaar"
test.routes.route1.ham = "eeeeeeeg"
test.routes.route2.foo = "12345"
test.routes.route2.ham = "abcde"
test.routes.route3.foo = "barrrrr"
test.routes.route3.ham = ""

test.test = ""

I get the following result using mix conform.effective

 [app: [routes: [route1: [foo: "baaaar", ham: "eeeeeeeg"],
   route2: [foo: "12345", ham: "abcde"], route3: [foo: "barrrrr", ham: "egg"]],
  test: ""]]

so the default value in app.test is overwritten by the empty string, whereas app.routes.route3.ham used the default value instead.

To me this seems to be quite inconsistent and was a surprise leading to an error.
Could you please make the behaviour consistent?

@0xAX
Copy link
Member

0xAX commented Nov 18, 2015

@grundrauschen will look and fix

@0xAX
Copy link
Member

0xAX commented Nov 18, 2015

@grundrauschen I've pushed possible fix, can you test it - #7

@0xAX
Copy link
Member

0xAX commented Nov 19, 2015

ah no, it is bad solution I think

@0xAX
Copy link
Member

0xAX commented Feb 18, 2016

@grundrauschen Can you test it?

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

No branches or pull requests

2 participants