volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Type assertion error when use yaml as config file #439

Closed ch3rub1m closed 5 years ago

ch3rub1m commented 5 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v3.1.0

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

panic: interface conversion: interface {} is map[interface {}]interface {}, not map[string]interface {}

Further information. What did you do, what did you expect?

For example, It's my yaml file:

mysql:
  dbname: auth
  host: localhost
  sslmode: "false"
  user: root
  whitelist:
  - users
aliases:
  tables:
  - name: users
    columns:
    - name: created_at
      alias: CreateTime

The viper will infer that aliases.tables and aliases.tables.columns are []map[interface{}]interface{} and it's different with toml.

However, in boilingcore/config.go there are many hardcode about type assertions, like something.(map[string]interface{}). It will cause crash if use yaml as config file.

ch3rub1m commented 5 years ago

I created a new PR #440. It used spf13/cast to cast interface{} to map[string]interface{} to avoided crash.

The package spf13/cast is the dependency of viper, so there is no introduced package.

aarondl commented 5 years ago

I've merged your PR. A part of me wanted to simply remove yaml support instead as that's a much better decision in the long run, but unfortunately there may be others that took advantage of our apathy when it came to using viper and just allowing all the file formats and that would essentially be a breaking change which isn't to be taken lightly. I'd urge you to stop using yaml now and forever, it's got too many features and as a consequence no trivial parser can possibly exist for it, it can possibly be used as an attack vector since it allows execution in certain contexts, even the creator (I've talked to him face to face on this subject) never intended for it to be used for config it was meant for data serialization, it's white space sensitive which can be damaging in certain contexts. There's almost no end to the reasons why one should -not- use it. Anyhow, I've spoken my piece on it. Enjoy your day, and thanks for the PR!