Repository: docker/docker-py

Issue:
Can't create config object
Much like https://github.com/docker/docker-py/issues/2025 the config model is failing to create a new object due to 'name' KeyError

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "docker\models\configs.py", line 10, in __repr__
    return f"<{self.__class__.__name__}: '{self.name}'>"
  File "docker\models\configs.py", line 14, in name
    return self.attrs['Spec']['Name']
```

This https://github.com/docker/docker-py/pull/2793 appears to be the fix that was implemented and should likely be implements for configs as well (if not other models that might have this issue)


Discussion:
@Josh-Klassen-Dejero 
Hello, I would like to contribute to this issue. May I ask you to put more detail to replicate the situation?
- OS
- Docker version
- docker-py version
- python version
- files you faced this problem

- Windows 10 Pro 64bit version 21H2 build 19044.2965
- Docker Desktop 4.19.0
- docker-py 6.0.1
- Python 3.8.10
- it happened for all config files
Can confirm. Any update about this problem?

Resolving patch:
diff --git a/docker/models/configs.py b/docker/models/configs.py
--- a/docker/models/configs.py
+++ b/docker/models/configs.py
@@ -30,6 +30,7 @@ class ConfigCollection(Collection):
 
     def create(self, **kwargs):
         obj = self.client.api.create_config(**kwargs)
+        obj.setdefault("Spec", {})["Name"] = kwargs.get("name")
         return self.prepare_model(obj)
     create.__doc__ = APIClient.create_config.__doc__
 


Test patch:
diff --git a/tests/unit/fake_api.py b/tests/unit/fake_api.py
--- a/tests/unit/fake_api.py
+++ b/tests/unit/fake_api.py
@@ -19,6 +19,8 @@
 FAKE_NODE_ID = '24ifsmvkjbyhk'
 FAKE_SECRET_ID = 'epdyrw4tsi03xy3deu8g8ly6o'
 FAKE_SECRET_NAME = 'super_secret'
+FAKE_CONFIG_ID = 'sekvs771242jfdjnvfuds8232'
+FAKE_CONFIG_NAME = 'super_config'
 
 # Each method is prefixed with HTTP method (get, post...)
 # for clarity and readability
@@ -512,6 +514,11 @@ def post_fake_secret():
     response = {'ID': FAKE_SECRET_ID}
     return status_code, response
 
+def post_fake_config():
+    status_code = 200
+    response = {'ID': FAKE_CONFIG_ID}
+    return status_code, response
+
 
 # Maps real api url to fake response callback
 prefix = 'http+docker://localhost'
@@ -630,4 +637,6 @@ def post_fake_secret():
     post_fake_network_disconnect,
     f'{prefix}/{CURRENT_VERSION}/secrets/create':
     post_fake_secret,
+    f'{prefix}/{CURRENT_VERSION}/configs/create':
+    post_fake_config,
 }
diff --git a/tests/unit/fake_api_client.py b/tests/unit/fake_api_client.py
--- a/tests/unit/fake_api_client.py
+++ b/tests/unit/fake_api_client.py
@@ -37,6 +37,7 @@ def make_fake_api_client(overrides=None):
         'create_host_config.side_effect': api_client.create_host_config,
         'create_network.return_value': fake_api.post_fake_network()[1],
         'create_secret.return_value': fake_api.post_fake_secret()[1],
+        'create_config.return_value': fake_api.post_fake_config()[1],
         'exec_create.return_value': fake_api.post_fake_exec_create()[1],
         'exec_start.return_value': fake_api.post_fake_exec_start()[1],
         'images.return_value': fake_api.get_fake_images()[1],
diff --git a/tests/unit/models_configs_test.py b/tests/unit/models_configs_test.py
new file mode 100644
--- /dev/null
+++ b/tests/unit/models_configs_test.py
@@ -0,0 +1,10 @@
+import unittest
+
+from .fake_api_client import make_fake_client
+from .fake_api import FAKE_CONFIG_NAME
+
+class CreateConfigsTest(unittest.TestCase):
+    def test_create_config(self):
+        client = make_fake_client()
+        config = client.configs.create(name="super_config", data="config")
+        assert config.__repr__() == "<Config: '{}'>".format(FAKE_CONFIG_NAME)