Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make check_exists cache negative results as well as positive ones #580

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion schema_salad/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@
raise ValidationException(f"Unsupported scheme in url: {url}")

def check_exists(self, url: str) -> bool:
if url in self.cache:
entry = self.cache.get(url)
if entry is False:
return False

Check warning on line 110 in schema_salad/fetcher.py

View check run for this annotation

Codecov / codecov/patch

schema_salad/fetcher.py#L110

Added line #L110 was not covered by tests
elif entry is not None:
return True

split = urllib.parse.urlsplit(url)
Expand All @@ -118,6 +121,7 @@
resp = self.session.head(url, allow_redirects=True)
resp.raise_for_status()
except Exception:
self.cache[url] = False
return False
self.cache[url] = True
return True
Expand Down