Repository: pypa/hatch

Issue:
"Self-referential environments" raises error
Hi

Thank you for a very nice tool :)

Reference to documentation: [Self-referential environments](https://hatch.pypa.io/latest/config/environment/overview/#self-referential-environments)

Using config:
```toml
[tool.hatch.envs.lock]
template = "lock"
```

```bash
$ hatch --version
Hatch, version 1.4.0
$ hatch run lock:pip list
KeyError: 'type'
```

Discussion:

Patch:
diff --git a/docs/history.md b/docs/history.md
index 8dde7476..f02541f2 100644
--- a/docs/history.md
+++ b/docs/history.md
@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 
 ### Unreleased
 
+***Fixed:***
+
+- Fix non-detached inheritance disabling for environments
+
 ### [1.4.0](https://github.com/pypa/hatch/releases/tag/hatch-v1.4.0) - 2022-08-06 ### {: #hatch-v1.4.0 }
 
 ***Added:***
diff --git a/src/hatch/project/config.py b/src/hatch/project/config.py
index a5db13b8..a821723b 100644
--- a/src/hatch/project/config.py
+++ b/src/hatch/project/config.py
@@ -426,8 +426,7 @@ def expand_script_commands(script_name, commands, config, seen, active):
 def _populate_default_env_values(env_name, data, config, seen, active):
     if env_name in seen:
         return
-    elif data.get('detached', False):
-        ensure_valid_environment(data)
+    elif data.pop('detached', False):
         data['template'] = env_name
         data['skip-install'] = True
 
@@ -440,6 +439,7 @@ def _populate_default_env_values(env_name, data, config, seen, active):
         active.append(env_name)
         raise ValueError(f'Circular inheritance detected for field `tool.hatch.envs.*.template`: {" -> ".join(active)}')
     elif template_name == env_name:
+        ensure_valid_environment(data)
         seen.add(env_name)
         return
 


Test patch:
diff --git a/tests/project/test_config.py b/tests/project/test_config.py
index 3f68823d..ee64e86f 100644
--- a/tests/project/test_config.py
+++ b/tests/project/test_config.py
@@ -174,13 +174,22 @@ class TestEnvs:
             'baz': {'type': 'virtual', 'scripts': {'cmd1': 'bar', 'cmd2': 'baz'}},
         }
 
+    def test_self_referential(self, isolation):
+        env_config = {'default': {'option1': 'foo'}, 'bar': {'template': 'bar'}}
+        project_config = ProjectConfig(isolation, {'envs': env_config}, PluginManager())
+
+        assert project_config.envs == {
+            'default': {'type': 'virtual', 'option1': 'foo'},
+            'bar': {'type': 'virtual'},
+        }
+
     def test_detached(self, isolation):
         env_config = {'default': {'option1': 'foo'}, 'bar': {'detached': True}}
         project_config = ProjectConfig(isolation, {'envs': env_config}, PluginManager())
 
         assert project_config.envs == {
             'default': {'type': 'virtual', 'option1': 'foo'},
-            'bar': {'type': 'virtual', 'detached': True, 'skip-install': True},
+            'bar': {'type': 'virtual', 'skip-install': True},
         }
 
     def test_matrices_not_array(self, isolation):