<#21162 local cache read and written to even with ...
# github-notifications
c
#21162 local cache read and written to even with --no-local-cache Issue created by cburroughs Setup With this handy test program running:
Copy code
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse, parse_qs
import hashlib

class RequestHandler(BaseHTTPRequestHandler):
    
    def do_GET(self):
        parsed_url = urlparse(self.path)
        query_params = parse_qs(parsed_url.query)
        
        self.send_response(200)

        if 'badger' in query_params:
            resp = '''
            Badger, badger, badger, badger
            Badger, badger, badger, badger
            Mushroom, mushroom
            '''.encode()
        else:
            resp = query_params['val'][0].encode()
        self.send_header('X-pants-sha256', hashlib.sha256(resp).hexdigest())
        self.send_header('X-pants-len', len(resp))
        self.end_headers()        
        print(query_params)

        self.wfile.write(resp)


host_name = 'localhost'
host_port = 8080
httpd = HTTPServer((host_name, host_port), RequestHandler)
print(f'Started HTTP server on {host_name}:{host_port}')
httpd.serve_forever()
And this BUILD file
Copy code
file(
    name="hello",
    source=http_source(
        url='<http://localhost:8080/hello?val=world>',
        #url='<http://localhost:8080/hello?val=galaxy>',
        #url='<http://localhost:8080/hello?val=world&badger=true>'                
        
        sha256="486ea46224d1bb4fb680f34f7c9ad96a8f24ec88be73ea8e5a6c65260e9cb8a7",
        len=5,
    ),
)


run_shell_command(
    name="meow",
    execution_dependencies=[":hello"],
    command="cat {chroot}/hello",
)
Cache despite --no-local-cache
Copy code
$ pants --local-store-dir=/tmp/web/000 --no-pantsd --no-local-cache  run :meow
world
$ du -hs /tmp/web/000
106K	/tmp/web/000
Now change the BUILD file to use
url='<http://localhost:8080/hello?val=galaxy>
Copy code
$ pants --local-store-dir=/tmp/web/000 --no-pantsd --no-local-cache  run :meow
world
(This should have been an error with nothing in the cache and the url/sha mistatch) Random Cache Dir Now compare this to:
Copy code
pants --local-store-dir=$(mktemp -u)  --no-pantsd --no-local-cache  run :meow
world
Change the BUILD file to use
url='<http://localhost:8080/hello?val=galaxy>
Copy code
$ pants --local-store-dir=$(mktemp -u)  --no-pantsd --no-local-cache  run :meow
16:09:18.58 [ERROR] 1 Exception encountered:

Engine traceback:
  in `run` goal

IntrinsicError: Error hashing/capturing URL fetch response: Downloaded file was larger than expected digest
My expectation from https://www.pantsbuild.org/2.20/reference/global-options#local_cache is that setting
--no-local-cache
doesn't use the local cache. Versions
pants_version = "2.21.0"
pantsbuild/pants