chimpler / pyhocon

HOCON parser for Python
Apache License 2.0
502 stars 118 forks source link

#256 - Process substitution overrides in order #257

Closed JettJones closed 3 years ago

JettJones commented 3 years ago

Fixing #256 - and a small radius around it.

The Scenario

Using hocon in a larger system where this came up.

keys: { something: "${lookup}-${name}" }

overridden by:
keys: { something: "${lookup}-legacy-name" }

During substitution & replacement, the following happened:

Starting queue had these substitutions: [${lookup}(parent), ${name}(parent), ${lookup}(child)]

  1. Process ${lookup}(parent), the result value still had -${name}, so this substitution stays in the set to re-process, and enqueues ${name}(2) at the end of the list.
  2. Process ${name}(parent) - this produces a static result string, and is removed.
  3. Process ${lookup}(child) - this produces a static result string, and is removed. (that's all the substitutions, so the loop restarts)
  4. Process ${lookup}(parent) - overwrites step 3. No overrides remain, so is removed.
  5. Process ${name}(2) - also overwrites step 3. No overrides remain, so is removed.

Proposed Fix:

When looking at a substitution, first check if it has a parent override, and if that parent is active in the substitution list. Wait for all parents to complete before processing the substitution.

This caused two test failures:

Testing

^ NamedTemporaryFile does not work on Windows (python.org) - I'll try to kick the tires in docker if there's traction for landing this.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.02%) to 95.377% when pulling 84344e0b7503fe15723577b81997dd9c607cbfc2 on JettJones:jettjones/bug256 into 07758b83be51f5f2d826ba127540d571cf55279a on chimpler:master.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.02%) to 95.377% when pulling 84344e0b7503fe15723577b81997dd9c607cbfc2 on JettJones:jettjones/bug256 into 07758b83be51f5f2d826ba127540d571cf55279a on chimpler:master.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.02%) to 95.377% when pulling 84344e0b7503fe15723577b81997dd9c607cbfc2 on JettJones:jettjones/bug256 into 07758b83be51f5f2d826ba127540d571cf55279a on chimpler:master.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.02%) to 95.377% when pulling 84344e0b7503fe15723577b81997dd9c607cbfc2 on JettJones:jettjones/bug256 into 07758b83be51f5f2d826ba127540d571cf55279a on chimpler:master.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.02%) to 95.377% when pulling 84344e0b7503fe15723577b81997dd9c607cbfc2 on JettJones:jettjones/bug256 into 07758b83be51f5f2d826ba127540d571cf55279a on chimpler:master.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.02%) to 95.377% when pulling 84344e0b7503fe15723577b81997dd9c607cbfc2 on JettJones:jettjones/bug256 into 07758b83be51f5f2d826ba127540d571cf55279a on chimpler:master.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.8%) to 96.181% when pulling 84344e0b7503fe15723577b81997dd9c607cbfc2 on JettJones:jettjones/bug256 into 07758b83be51f5f2d826ba127540d571cf55279a on chimpler:master.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.02%) to 95.377% when pulling 84344e0b7503fe15723577b81997dd9c607cbfc2 on JettJones:jettjones/bug256 into 07758b83be51f5f2d826ba127540d571cf55279a on chimpler:master.

darthbear commented 3 years ago

Thank you @JettJones for the fix!