ethereum / ethereum/populus

Incorrect/Undefined behavior when populus writes to configuration values under a `$ref`

Open
#304 4 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
No language data
Stars
319
Forks
110
PR merge metrics
No merged PRs in 30d

Description

* Populus Version: 1.6.9
* OS: all

### What was wrong?

Populus is not correctly handling the writing of configuration values into `$ref` based configuration sections.

Given the following configuration:

```
{
"foo": {"$ref": "bar"},
"bar": {"baz": 3},
}
```

When populus reads this, what it sees is:

```
{
"foo": {"baz": 3},
"bar": {"baz": 3},
}
```

The error occurs when a configuration value is written to a key under `foo`. Currently, if you were to set `foo.test = 3` this is the result:

```
{
"foo": {
"$ref": "bar",
"test": 3
},
"bar": {"baz": 3},
}
```

This should result in an invalid configuration once #283 has been addressed.

### How can it be fixed?

Fixing this is going to require extending the configuration API as the current API does not have a convention to gracefully handle the case where a configuration value is written into a `$ref`. Since `$ref` values are designed to be *shared* resources across the config file, it doesn't make sense to write these values into the target of the `$ref`.

Instead we need to introduce a new API, `$extends`.

When the configuration file encounters an `{"$extends": "path.to.section", ...}` it should perform a deep merge of the local configuration and the configuration found under `path.to.section`.

The result is that when populus encounters the following configuration:

```
{
"foo": {
"$extends": "bar",
"test": 3
},
"bar": {"baz": 3},
}
```

What it actually sees is:

```
{
"foo": {
"baz": 3,
"test": 3
},
"bar": {"baz": 3},
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.