Repository: gabrieldemarmiesse/python-on-whales (language: python)

Issue:
Support podman parsing
```Python console
>>> podman=python_on_whales.DockerClient(client_binary='podman')
>>> podman.container.inspect('176579f64e64a8fc7c0f29250301a88977c3583204b0f7a0a080dbf8ea53154f')                                     [648/1832]
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/python_on_whales/client_config.py", line 242, in _fetch_and_parse_inspect_result
    return self._parse_json_object(json_object)
  File "/usr/lib/python3.9/site-packages/python_on_whales/components/container/cli_wrapper.py", line 60, in _parse_json_object
    return ContainerInspectResult.parse_obj(json_object)
  File "pydantic/main.py", line 521, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for ContainerInspectResult
Config -> Entrypoint
  value is not a valid list (type=type_error.list)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/python_on_whales/components/container/cli_wrapper.py", line 880, in inspect
    return Container(self.client_config, x)
  File "/usr/lib/python3.9/site-packages/python_on_whales/components/container/cli_wrapper.py", line 44, in __init__
    super().__init__(client_config, "id", reference, is_immutable_id)
  File "/usr/lib/python3.9/site-packages/python_on_whales/client_config.py", line 184, in __init__
    self._fetch_and_parse_inspect_result(reference_or_id)
  File "/usr/lib/python3.9/site-packages/python_on_whales/client_config.py", line 248, in _fetch_and_parse_inspect_result
    raise ParsingError(
python_on_whales.client_config.ParsingError: There was an error parsing the json response from the Docker daemon.
This is a bug with python-on-whales itself. Please head to
https://github.com/gabrieldemarmiesse/python-on-whales/issues
and open an issue. You should copy this error message and
the json response from the Docker daemon. The json response was put
in /tmp/tmp7runnyta.json because it's a bit too big to be printed
on the screen. Make sure that there are no sensitive data in the
json file before copying it in the github issue.
>>> o=json.loads(pathlib.Path('/tmp/tmp7runnyta.json').read_text())
>>> o[0]['Config']['Entrypoint']
''
````

Workaround **for exactly this problem**:
```python
mf = python_on_whales.components.container.models.ContainerConfig.__fields__['entrypoint']
mf2 = pydantic.fields.ModelField.infer(
    name=mf.name,
    value=None,
    annotation=typing.Union[typing.List[str], str],
    class_validators=mf.class_validators,
    config=mf.model_config)
for k in mf.__slots__:
    setattr(mf, k, getattr(mf2, k))
```


Discussion / hints:
Thank you for the bug report! I should be able to fix this quickly! 
Note, that there can be more model differences not caught by me.
Sorry for this.

Fix patch:
diff --git a/python_on_whales/components/container/models.py b/python_on_whales/components/container/models.py
index 190574fc..1506e96d 100644
--- a/python_on_whales/components/container/models.py
+++ b/python_on_whales/components/container/models.py
@@ -1,6 +1,6 @@
 from datetime import datetime
 from pathlib import Path
-from typing import Any, Dict, List, Tuple
+from typing import Any, Dict, List, Tuple, Union
 
 import pydantic
 
@@ -227,7 +227,7 @@ class ContainerConfig(DockerCamelModel):
     image: str
     volumes: dict
     working_dir: Path
-    entrypoint: List[str]
+    entrypoint: Union[List[str], str]
     network_disabled: bool
     mac_address: str
     on_build: List[str]


Test patch:
diff --git a/tests/python_on_whales/components/jsons/containers/20.json b/tests/python_on_whales/components/jsons/containers/20.json
new file mode 100644
index 00000000..869f75c3
--- /dev/null
+++ b/tests/python_on_whales/components/jsons/containers/20.json
@@ -0,0 +1,190 @@
+{
+    "Id": "f00ccd0fd33d59f84cd5f6cc7420127a410a23d1beb40e899a9e617e5842325e",
+    "Created": "2020-11-08T13:31:33.2980657Z",
+    "Path": "buildkitd",
+    "Args": [],
+    "State": {
+        "Status": "running",
+        "Running": true,
+        "Paused": false,
+        "Restarting": false,
+        "OOMKilled": false,
+        "Dead": false,
+        "Pid": 18803,
+        "ExitCode": 0,
+        "Error": "",
+        "StartedAt": "2020-11-08T13:31:33.7332351Z",
+        "FinishedAt": "0001-01-01T00:00:00Z"
+    },
+    "Image": "sha256:975176a9c454d4020440696d3397f1df9c399c5f8ac2e35484e11884da25603f",
+    "ResolvConfPath": "/var/lib/docker/containers/f00ccd0fd33d59f84cd5f6cc7420127a410a23d1beb40e899a9e617e5842325e/resolv.conf",
+    "HostnamePath": "/var/lib/docker/containers/f00ccd0fd33d59f84cd5f6cc7420127a410a23d1beb40e899a9e617e5842325e/hostname",
+    "HostsPath": "/var/lib/docker/containers/f00ccd0fd33d59f84cd5f6cc7420127a410a23d1beb40e899a9e617e5842325e/hosts",
+    "LogPath": "/var/lib/docker/containers/f00ccd0fd33d59f84cd5f6cc7420127a410a23d1beb40e899a9e617e5842325e/f00ccd0fd33d59f84cd5f6cc7420127a410a23d1beb40e899a9e617e5842325e-json.log",
+    "Name": "/buildx_buildkit_wonderful_mahavira0",
+    "RestartCount": 0,
+    "Driver": "overlay2",
+    "Platform": "linux",
+    "MountLabel": "",
+    "ProcessLabel": "",
+    "AppArmorProfile": "",
+    "ExecIDs": null,
+    "HostConfig": {
+        "Binds": null,
+        "ContainerIDFile": "",
+        "LogConfig": {
+            "Type": "json-file",
+            "Config": {}
+        },
+        "NetworkMode": "default",
+        "PortBindings": null,
+        "RestartPolicy": {
+            "Name": "",
+            "MaximumRetryCount": 0
+        },
+        "AutoRemove": false,
+        "VolumeDriver": "",
+        "VolumesFrom": null,
+        "CapAdd": null,
+        "CapDrop": null,
+        "Capabilities": null,
+        "Dns": null,
+        "DnsOptions": null,
+        "DnsSearch": null,
+        "ExtraHosts": null,
+        "GroupAdd": null,
+        "IpcMode": "private",
+        "Cgroup": "",
+        "Links": null,
+        "OomScoreAdj": 0,
+        "PidMode": "",
+        "Privileged": true,
+        "PublishAllPorts": false,
+        "ReadonlyRootfs": false,
+        "SecurityOpt": [
+            "label=disable"
+        ],
+        "UTSMode": "",
+        "UsernsMode": "",
+        "ShmSize": 67108864,
+        "Runtime": "runc",
+        "ConsoleSize": [
+            0,
+            0
+        ],
+        "Isolation": "",
+        "CpuShares": 0,
+        "Memory": 0,
+        "NanoCpus": 0,
+        "CgroupParent": "",
+        "BlkioWeight": 0,
+        "BlkioWeightDevice": null,
+        "BlkioDeviceReadBps": null,
+        "BlkioDeviceWriteBps": null,
+        "BlkioDeviceReadIOps": null,
+        "BlkioDeviceWriteIOps": null,
+        "CpuPeriod": 0,
+        "CpuQuota": 0,
+        "CpuRealtimePeriod": 0,
+        "CpuRealtimeRuntime": 0,
+        "CpusetCpus": "",
+        "CpusetMems": "",
+        "Devices": null,
+        "DeviceCgroupRules": null,
+        "DeviceRequests": null,
+        "KernelMemory": 0,
+        "KernelMemoryTCP": 0,
+        "MemoryReservation": 0,
+        "MemorySwap": 0,
+        "MemorySwappiness": null,
+        "OomKillDisable": false,
+        "PidsLimit": null,
+        "Ulimits": null,
+        "CpuCount": 0,
+        "CpuPercent": 0,
+        "IOMaximumIOps": 0,
+        "IOMaximumBandwidth": 0,
+        "MaskedPaths": null,
+        "ReadonlyPaths": null
+    },
+    "GraphDriver": {
+        "Data": {
+            "LowerDir": "/var/lib/docker/overlay2/a8c0fd65e99075e3843477251d0cba5848d903ff3c2eaeac64906cb58f557620-init/diff:/var/lib/docker/overlay2/1f646bf8f494f89abe04515c5e26a07b14ff2381898d5bc23150b71223486810/diff:/var/lib/docker/overlay2/e765c5ab67d5ddce8f0a2005d07e7b17a0b4c88e8917fb7a7708263ef3684f43/diff:/var/lib/docker/overlay2/b6ee00396aba242b95e45f1aabe9180cc8323e406d56c61ab872f8df7addcbb6/diff:/var/lib/docker/overlay2/20845ec26d909c01d7669569a40aa40aa1f651802445e772a252c3a5f65217e4/diff",
+            "MergedDir": "/var/lib/docker/overlay2/a8c0fd65e99075e3843477251d0cba5848d903ff3c2eaeac64906cb58f557620/merged",
+            "UpperDir": "/var/lib/docker/overlay2/a8c0fd65e99075e3843477251d0cba5848d903ff3c2eaeac64906cb58f557620/diff",
+            "WorkDir": "/var/lib/docker/overlay2/a8c0fd65e99075e3843477251d0cba5848d903ff3c2eaeac64906cb58f557620/work"
+        },
+        "Name": "overlay2"
+    },
+    "Mounts": [
+        {
+            "Type": "volume",
+            "Name": "698f8fe4ad448d1f4fb7599ee8d225300046e6b33b7854d9d2173d152a85b5fc",
+            "Source": "/var/lib/docker/volumes/698f8fe4ad448d1f4fb7599ee8d225300046e6b33b7854d9d2173d152a85b5fc/_data",
+            "Destination": "/var/lib/buildkit",
+            "Driver": "local",
+            "Mode": "",
+            "RW": true,
+            "Propagation": ""
+        }
+    ],
+    "Config": {
+        "Hostname": "f00ccd0fd33d",
+        "Domainname": "",
+        "User": "",
+        "AttachStdin": false,
+        "AttachStdout": false,
+        "AttachStderr": false,
+        "Tty": false,
+        "OpenStdin": false,
+        "StdinOnce": false,
+        "Env": [
+            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
+        ],
+        "Cmd": null,
+        "Image": "moby/buildkit:buildx-stable-1",
+        "Volumes": {
+            "/var/lib/buildkit": {}
+        },
+        "WorkingDir": "",
+        "Entrypoint": "buildkitd",
+        "OnBuild": null,
+        "Labels": {}
+    },
+    "NetworkSettings": {
+        "Bridge": "",
+        "SandboxID": "55436b0f014543443154b5baeac04b9315a42b8e8bdbc7716d52cb6a8590e79c",
+        "HairpinMode": false,
+        "LinkLocalIPv6Address": "",
+        "LinkLocalIPv6PrefixLen": 0,
+        "Ports": {},
+        "SandboxKey": "/var/run/docker/netns/55436b0f0145",
+        "SecondaryIPAddresses": null,
+        "SecondaryIPv6Addresses": null,
+        "EndpointID": "284f4a0a0f0851936edc174b728a6facd4efad0a6aa390b2577aa7da584dfdd1",
+        "Gateway": "172.17.0.1",
+        "GlobalIPv6Address": "",
+        "GlobalIPv6PrefixLen": 0,
+        "IPAddress": "172.17.0.2",
+        "IPPrefixLen": 16,
+        "IPv6Gateway": "",
+        "MacAddress": "02:42:ac:11:00:02",
+        "Networks": {
+            "bridge": {
+                "IPAMConfig": null,
+                "Links": null,
+                "Aliases": null,
+                "NetworkID": "c2dd37ff304a8596e4e1f9a2fbc0d26338a782a749617cb3f2699f5def0911a1",
+                "EndpointID": "284f4a0a0f0851936edc174b728a6facd4efad0a6aa390b2577aa7da584dfdd1",
+                "Gateway": "172.17.0.1",
+                "IPAddress": "172.17.0.2",
+                "IPPrefixLen": 16,
+                "IPv6Gateway": "",
+                "GlobalIPv6Address": "",
+                "GlobalIPv6PrefixLen": 0,
+                "MacAddress": "02:42:ac:11:00:02",
+                "DriverOpts": null
+            }
+        }
+    }
+}