diff --git a/pyhocon/config_tree.py b/pyhocon/config_tree.py
index 60b2d88..d045c7b 100644
--- a/pyhocon/config_tree.py
+++ b/pyhocon/config_tree.py
@@ -70,6 +70,9 @@ class ConfigTree(OrderedDict):
                             type=l.__class__.__name__)
                     )
             else:
+                # if there was an override keep overide value
+                if isinstance(value, ConfigValues):
+                    value.overriden_value = self.get(key_elt, None)
                 super(ConfigTree, self).__setitem__(key_elt, value)
         else:
             next_config_tree = super(ConfigTree, self).get(key_elt)

${?foo} unsets previous value if new is undefined
pyhocon==0.3.2

Apparently `${?VAR_NAME}` no longer complains about undefined variables but is seems to be unsetting the key. My expectation is that `${?foo}` would leave the key referencing the last value unless it had something to replace it with.

```
...
  File "/Users/bkuberek/Development/people-service/.venv/lib/python2.7/site-packages/pyhocon/__init__.py", line 203, in parse
    ConfigParser._resolve_substitutions(config, substitutions)
  File "/Users/bkuberek/Development/people-service/.venv/lib/python2.7/site-packages/pyhocon/__init__.py", line 246, in _resolve_substitutions
    is_optional_resolved, resolved_value = ConfigParser._resolve_variable(config, substitution)
  File "/Users/bkuberek/Development/people-service/.venv/lib/python2.7/site-packages/pyhocon/__init__.py", line 228, in _resolve_variable
    col=col(substitution.loc, substitution.instring)))
pyhocon.exceptions.ConfigSubstitutionException: Cannot resolve variable ${database.name} (line: 20, col: 102)
```

Here is my configuration:
```
{
  database {
    host = "localhost"
    port = "5432"
    user = "people"
    name = "peopledb"
    pass = "dev"
    url = "postgresql://"${database.user}":"${database.pass}"@"${database.host}":"${database.port}"/"${database.name}

    # Override from environment variables if they exist
    host = ${?DB_HOST}
    port = ${?DB_PORT}
    user = ${?DB_USER}
    name = ${?DB_NAME}
    pass = ${?DB_PASS}
  }
}
```

diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py
index b343d35..c0dbb15 100644
--- a/tests/test_config_parser.py
+++ b/tests/test_config_parser.py
@@ -797,7 +797,21 @@ class TestConfigParser(object):
         assert config['database.user'] == 'test_user'
         assert config['database.pass'] == 'test_pass'
 
-    def test_substitution_override(self):
+    def test_substitution_flat_override(self):
+        config = ConfigFactory.parse_string(
+            """
+            database {
+                name = peopledb
+                pass = peoplepass
+                name = ${?NOT_EXISTS}
+                pass = ${?NOT_EXISTS}
+            }
+            """)
+
+        assert config['database.name'] == 'peopledb'
+        assert config['database.pass'] == 'peoplepass'
+
+    def test_substitution_nested_override(self):
         config = ConfigFactory.parse_string(
             """
             database {

pip install -e .
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.9
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
exceptiongroup==1.2.2
iniconfig==2.1.0
packaging==24.2
pluggy==1.5.0
-e git+https://github.com/chimpler/pyhocon.git@1dfded0867d7de333d2ee9bc90ee25b2d690f819#egg=pyhocon
pyparsing==2.0.3
pytest==8.3.5
tomli==2.2.1

name: pyhocon
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - exceptiongroup==1.2.2
      - iniconfig==2.1.0
      - packaging==24.2
      - pluggy==1.5.0
      - pyparsing==2.0.3
      - pytest==8.3.5
      - tomli==2.2.1
prefix: /opt/conda/envs/pyhocon

tests/test_config_parser.py::TestConfigParser::test_substitution_flat_override
tests/test_config_parser.py::TestConfigParser::test_parse_simple_value tests/test_config_parser.py::TestConfigParser::test_parse_with_enclosing_brace tests/test_config_parser.py::TestConfigParser::test_parse_with_enclosing_square_bracket tests/test_config_parser.py::TestConfigParser::test_quoted_key_with_dots tests/test_config_parser.py::TestConfigParser::test_comma_to_separate_expr tests/test_config_parser.py::TestConfigParser::test_dict_merge tests/test_config_parser.py::TestConfigParser::test_parse_with_comments tests/test_config_parser.py::TestConfigParser::test_missing_config tests/test_config_parser.py::TestConfigParser::test_parse_null tests/test_config_parser.py::TestConfigParser::test_parse_empty tests/test_config_parser.py::TestConfigParser::test_parse_override tests/test_config_parser.py::TestConfigParser::test_concat_dict tests/test_config_parser.py::TestConfigParser::test_concat_string tests/test_config_parser.py::TestConfigParser::test_concat_list tests/test_config_parser.py::TestConfigParser::test_bad_concat tests/test_config_parser.py::TestConfigParser::test_string_substitutions tests/test_config_parser.py::TestConfigParser::test_int_substitutions tests/test_config_parser.py::TestConfigParser::test_cascade_string_substitutions tests/test_config_parser.py::TestConfigParser::test_dict_substitutions tests/test_config_parser.py::TestConfigParser::test_list_substitutions tests/test_config_parser.py::TestConfigParser::test_non_existent_substitution tests/test_config_parser.py::TestConfigParser::test_non_compatible_substitution tests/test_config_parser.py::TestConfigParser::test_concat_multi_line_string tests/test_config_parser.py::TestConfigParser::test_concat_multi_line_list tests/test_config_parser.py::TestConfigParser::test_concat_multi_line_dict tests/test_config_parser.py::TestConfigParser::test_parse_URL_from_samples tests/test_config_parser.py::TestConfigParser::test_include_dict_from_samples tests/test_config_parser.py::TestConfigParser::test_list_of_dicts tests/test_config_parser.py::TestConfigParser::test_list_of_lists tests/test_config_parser.py::TestConfigParser::test_list_of_dicts_with_merge tests/test_config_parser.py::TestConfigParser::test_list_of_lists_with_merge tests/test_config_parser.py::TestConfigParser::test_invalid_assignment tests/test_config_parser.py::TestConfigParser::test_invalid_dict tests/test_config_parser.py::TestConfigParser::test_include_list tests/test_config_parser.py::TestConfigParser::test_include_dict tests/test_config_parser.py::TestConfigParser::test_substitution_override tests/test_config_parser.py::TestConfigParser::test_substitution_nested_override tests/test_config_parser.py::TestConfigParser::test_optional_substitution tests/test_config_parser.py::TestConfigParser::test_substitution_cycle tests/test_config_parser.py::TestConfigParser::test_assign_number_with_eol tests/test_config_parser.py::TestConfigParser::test_assign_strings_with_eol tests/test_config_parser.py::TestConfigParser::test_assign_list_numbers_with_eol tests/test_config_parser.py::TestConfigParser::test_assign_list_strings_with_eol tests/test_config_parser.py::TestConfigParser::test_assign_dict_strings_with_equal_sign_with_eol tests/test_config_parser.py::TestConfigParser::test_assign_dict_strings_no_equal_sign_with_eol
pyhocon/config_tree.py
pyhocon/config_tree.py