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

analytics: ignore request.post errors #3292

Merged
merged 1 commit into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
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
analytics: ignore request.post errors
Users have been complaining about dvc analytics errors when they are not
connected to the internet.
  • Loading branch information
efiop committed Feb 9, 2020
commit 2d9f263691e3a7896061a954ed579b1c578b0aa1
5 changes: 4 additions & 1 deletion dvc/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def send(report):
headers = {"content-type": "application/json"}

with open(report, "rb") as fobj:
requests.post(url, data=fobj, headers=headers, timeout=5)
try:
requests.post(url, data=fobj, headers=headers, timeout=5)
except requests.exceptions.RequestException:
logger.debug("failed to send analytics report", exc_info=True)

os.remove(report)

Expand Down
11 changes: 7 additions & 4 deletions tests/unit/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ def test_runtime_info(tmp_global_config):

@mock.patch("requests.post")
def test_send(mock_post, tmp_path):
import requests

url = "https://analytics.dvc.org"
report = {"name": "dummy report"}
fname = str(tmp_path / "report")
report_file = tmp_path / "report"

with open(fname, "w") as fobj:
json.dump(report, fobj)
report_file.write_text(json.dumps(report))
mock_post.side_effect = requests.exceptions.RequestException

analytics.send(fname)
analytics.send(str(report_file))
assert mock_post.called
assert mock_post.call_args.args[0] == url
assert not report_file.exists()


@pytest.mark.parametrize(
Expand Down