Repository: mkdocs/mkdocs

Issue:
Config.validate keeps 'mdx_configs' values across different instances
```python
import mkdocs.config

# 1. OK
conf = mkdocs.config.Config(mkdocs.config.DEFAULT_SCHEMA)
conf.load_dict({'site_name': 'foo'})
conf.validate()
assert conf['mdx_configs'].get('toc') == None

# 2. OK
conf = mkdocs.config.Config(mkdocs.config.DEFAULT_SCHEMA)
conf.load_dict({'site_name': 'foo', 'markdown_extensions': [{"toc": {"permalink": "aaa"}}]})
conf.validate()
assert conf['mdx_configs'].get('toc') == {'permalink': 'aaa'}

# 3. Identical to 1 but not OK.
conf = mkdocs.config.Config(mkdocs.config.DEFAULT_SCHEMA)
conf.load_dict({'site_name': 'foo'})
conf.validate()
assert conf['mdx_configs'].get('toc') == None
# fails, actually is {'permalink': 'aaa'}
```


Discussion:

Resolving patch:
diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py
--- a/mkdocs/config/config_options.py
+++ b/mkdocs/config/config_options.py
@@ -623,7 +623,6 @@ def __init__(self, builtins=None, configkey='mdx_configs', **kwargs):
         super().__init__(**kwargs)
         self.builtins = builtins or []
         self.configkey = configkey
-        self.configdata = {}
 
     def validate_ext_cfg(self, ext, cfg):
         if not isinstance(ext, str):
@@ -635,6 +634,7 @@ def validate_ext_cfg(self, ext, cfg):
         self.configdata[ext] = cfg
 
     def run_validation(self, value):
+        self.configdata = {}
         if not isinstance(value, (list, tuple, dict)):
             raise ValidationError('Invalid Markdown Extensions configuration')
         extensions = []


Test patch:
diff --git a/mkdocs/tests/config/config_tests.py b/mkdocs/tests/config/config_tests.py
--- a/mkdocs/tests/config/config_tests.py
+++ b/mkdocs/tests/config/config_tests.py
@@ -283,18 +283,24 @@ def test_doc_dir_in_site_dir(self):
             self.assertEqual(len(errors), 1)
             self.assertEqual(warnings, [])
 
-    def testConfigInstancesUnique(self):
-        conf = mkdocs.config.Config(mkdocs.config.defaults.get_schema())
-        conf.load_dict({'site_name': 'foo'})
-        conf.validate()
-        self.assertIsNone(conf['mdx_configs'].get('toc'))
+    def test_multiple_markdown_config_instances(self):
+        # This had a bug where an extension config would persist to separate
+        # config instances that didn't specify extensions.
+        schema = config.defaults.get_schema()
 
-        conf = mkdocs.config.Config(mkdocs.config.defaults.get_schema())
-        conf.load_dict({'site_name': 'foo', 'markdown_extensions': [{"toc": {"permalink": "aaa"}}]})
+        conf = config.Config(schema=schema)
+        conf.load_dict(
+            {
+                'site_name': 'Example',
+                'markdown_extensions': [{'toc': {'permalink': '##'}}],
+            }
+        )
         conf.validate()
-        self.assertEqual(conf['mdx_configs'].get('toc'), {'permalink': 'aaa'})
+        self.assertEqual(conf['mdx_configs'].get('toc'), {'permalink': '##'})
 
-        conf = mkdocs.config.Config(mkdocs.config.defaults.get_schema())
-        conf.load_dict({'site_name': 'foo'})
+        conf = config.Config(schema=schema)
+        conf.load_dict(
+            {'site_name': 'Example'},
+        )
         conf.validate()
         self.assertIsNone(conf['mdx_configs'].get('toc'))