# Inconsistent caching behaviour

**URL:** <https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225>\
**Category:** Caching Dependencies\
**Tags:** 2.0, python\
**Created:** [September 18, 2018, 3:48pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225 "2018-09-18T15:48:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DroneKid](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dronekid/32/19194_2.png) [@DroneKid](https://discuss.circleci.com/u/DroneKid)\
**Post date:** [September 18, 2018, 3:48pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225/1 "2018-09-18T15:48:26Z")

</div>

Hi All!

I’m experiencing inconsistent behavour when doing `pip install` over restored `venv`. Pip install has some version conflict warning (another issue), which passes and gets things installed first time. But when rebuild happens and `venv` is restored from the cache, pip fails hard with version inconsistencies. The weird part is that if I rebuild with ssh enabled and then execute the same `pip install` commands in the container, everything is fine.

Any ideas?  
A.

```auto
  test:
    docker:
      - image: circleci/python:3.6.5
    steps:
      - checkout
      - restore_cache:
          keys:
          - v3-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "setup.py"}}
      - run:
          name: Install dependencies
          command: |
            virtualenv venv --python=python3.6
            . venv/bin/activate
            pip install -r requirements.txt --extra-index-url https://xxxx --trusted-host xxxx
      - save_cache:
          paths:
            - ./venv
          key: v3-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "setup.py"}}
      - run:
          name: run tests
          command: |
            . venv/bin/activate
            pytest

```

---

<div class="post-metadata">

**Author:** ![Cormac](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cormac/32/18955_2.png) [@Cormac](https://discuss.circleci.com/u/Cormac)\
**Post date:** [September 18, 2018, 4:01pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225/2 "2018-09-18T16:01:56Z")

</div>

When you rebuild, are you doing so without cache? If so, it’s quite possible that the cache is causing this, and incrementing the cache key would be a fix (v3 to v4).

---

<div class="post-metadata">

**Author:** ![DroneKid](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dronekid/32/19194_2.png) [@DroneKid](https://discuss.circleci.com/u/DroneKid)\
**Post date:** [September 18, 2018, 4:04pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225/3 "2018-09-18T16:04:05Z")

</div>

I rebuild with cache. Bumping cache version helps, because install succeedes when there is no cache found. But when a cache is found, it fails.

---

<div class="post-metadata">

**Author:** ![Cormac](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cormac/32/18955_2.png) [@Cormac](https://discuss.circleci.com/u/Cormac)\
**Post date:** [September 21, 2018, 3:45pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225/4 "2018-09-21T15:45:20Z")

</div>

Could you post a link to a build where you’re building without cache, and one where you’re building with cache? Only CircleCI employees will be able to see the builds, unless they’re open source.

---

<div class="post-metadata">

**Author:** ![DroneKid](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dronekid/32/19194_2.png) [@DroneKid](https://discuss.circleci.com/u/DroneKid)\
**Post date:** [September 21, 2018, 4:16pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225/5 "2018-09-21T16:16:00Z")

</div>

He is the build where cache is not found (success):  
[https://circleci.com/gh/integrateai/webservice/294](https://circleci.com/gh/integrateai/webservice/294)  
Here is the rebuild of the same one and it found cache from the previous run:  
[https://circleci.com/gh/integrateai/webservice/295](https://circleci.com/gh/integrateai/webservice/295)

---

<div class="post-metadata">

**Author:** ![Cormac](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cormac/32/18955_2.png) [@Cormac](https://discuss.circleci.com/u/Cormac)\
**Post date:** [September 21, 2018, 6:58pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225/6 "2018-09-21T18:58:47Z")

</div>

It looks like the venv is succeeding, and the pip command is failing. I’m not exactly sure why that is though. I’ll look at this further.

---

<div class="post-metadata">

**Author:** ![DroneKid](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dronekid/32/19194_2.png) [@DroneKid](https://discuss.circleci.com/u/DroneKid)\
**Post date:** [September 21, 2018, 7:14pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225/7 "2018-09-21T19:14:36Z")

</div>

Exactly. Because the same pip command is OK the first time. Moreover, if you rerun with ssh, login there and try executing pip from shell, it runs with no problem.  
We fixed this build by fixing pip warnings, but I’m just curious about this behaviour. It might suggest some CircleCI bug.

---

<div class="post-metadata">

**Author:** ![Cormac](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cormac/32/18955_2.png) [@Cormac](https://discuss.circleci.com/u/Cormac)\
**Post date:** [September 21, 2018, 7:16pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225/8 "2018-09-21T19:16:08Z")

</div>

Glad to hear you fixed it at least – I’ll look into this further after the weekend.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [December 20, 2018, 7:16pm UTC](https://discuss.circleci.com/t/inconsistent-caching-behaviour/25225/9 "2018-12-20T19:16:09Z")

</div>

Closed on December 20, 2018, 7:16pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
