Repository: docker/docker-py

Issue:
Pull image by full digest is broken in 3.0.1
Using `python3` and `3.0.1` version - this can be reproduced as

```
>>> import docker
>>> client = docker.from_env()
>>> client.images.pull('python@sha256:7c3028aa4b9a30a34ce778b1fd4f460c9cdf174515a94641a89ef40c115b51e5')
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/docker/api/client.py", line 223, in _raise_for_status
    response.raise_for_status()
  File "/usr/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://192.168.99.100:2376/v1.35/images/python:sha256:7c3028aa4b9a30a34ce778b1fd4f460c9cdf174515a94641a89ef40c115b51e5/json

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/docker/models/images.py", line 311, in pull
    return self.get('{0}:{1}'.format(repository, tag))
  File "/usr/lib/python3.6/site-packages/docker/models/images.py", line 212, in get
    return self.prepare_model(self.client.api.inspect_image(name))
  File "/usr/lib/python3.6/site-packages/docker/utils/decorators.py", line 19, in wrapped
    return f(self, resource_id, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/docker/api/image.py", line 241, in inspect_image
    self._get(self._url("/images/{0}/json", image)), True
  File "/usr/lib/python3.6/site-packages/docker/api/client.py", line 229, in _result
    self._raise_for_status(response)
  File "/usr/lib/python3.6/site-packages/docker/api/client.py", line 225, in _raise_for_status
    raise create_api_error_from_http_exception(e)
  File "/usr/lib/python3.6/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 400 Client Error: Bad Request ("no such image: python:sha256:7c3028aa4b9a30a34ce778b1fd4f460c9cdf174515a94641a89ef40c115b51e5: invalid reference format")
```

Downgrading to `2.7.0` solves the issue.


Discussion:
Thanks for the report!

Resolving patch:
diff --git a/docker/models/images.py b/docker/models/images.py
--- a/docker/models/images.py
+++ b/docker/models/images.py
@@ -314,7 +314,9 @@ def pull(self, repository, tag=None, **kwargs):
 
         self.client.api.pull(repository, tag=tag, **kwargs)
         if tag:
-            return self.get('{0}:{1}'.format(repository, tag))
+            return self.get('{0}{2}{1}'.format(
+                repository, tag, '@' if tag.startswith('sha256:') else ':'
+            ))
         return self.list(repository)
 
     def push(self, repository, tag=None, **kwargs):


Test patch:
diff --git a/tests/integration/models_images_test.py b/tests/integration/models_images_test.py
--- a/tests/integration/models_images_test.py
+++ b/tests/integration/models_images_test.py
@@ -74,6 +74,15 @@ def test_pull_with_tag(self):
         image = client.images.pull('alpine', tag='3.3')
         assert 'alpine:3.3' in image.attrs['RepoTags']
 
+    def test_pull_with_sha(self):
+        image_ref = (
+            'hello-world@sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b95'
+            '59b27182d3fa80ce3f7'
+        )
+        client = docker.from_env(version=TEST_API_VERSION)
+        image = client.images.pull(image_ref)
+        assert image_ref in image.attrs['RepoDigests']
+
     def test_pull_multiple(self):
         client = docker.from_env(version=TEST_API_VERSION)
         images = client.images.pull('hello-world')