ebmdatalab / openprescribing

A Django app providing a REST API and dashboards for the HSCIC's GP prescribing data
https://openprescribing.net
MIT License
97 stars 26 forks source link

Images broken in June alerts #1087

Closed HelenCEBM closed 5 years ago

HelenCEBM commented 6 years ago

Might be related to #1028 but images were broken in email alerts last month image

This seems to be the case in gmail and outlook and for multiple recipients

sebbacon commented 6 years ago

Did you personally receive one that didn't work?

If so, please can you copy and paste the full source code (e.g. in gmail it's the "show original" option)

HelenCEBM commented 6 years ago

Delivered-To: ebmdatalab17@gmail.com Received: by 2002:a25:404c:0:0:0:0:0 with SMTP id n73-v6csp2145983yba; Thu, 30 Aug 2018 11:10:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYc4/5252DxdH74vNqim5UW6QvzN61p/NNEUFZHz7whJ6/0flmji+J86zURpHgbMoNGEuH6 X-Received: by 2002:a02:602a:: with SMTP id i42-v6mr10398932jac.95.1535652613068; Thu, 30 Aug 2018 11:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535652613; cv=none; d=google.com; s=arc-20160816; b=H/HBa9Du1ZULNdx5AmtVE1h9XsKGXDbwMEA+wDanF4NpdKBs9CbFEbrlYzwamgw8iH VhJIJbhGEv0HR3sDjA9e6Ge6kzJAYHu5KsdEZU9BPUyzm9Ga4E+1BZxa6w+ZSfhjcSI0 L7J4YCkAVpDQ5LjJi+Ktw8o4/DehCI0t92hAvsuGd2tgKw2fELZIUSIMQYXkduFQkwgE xqXkRDUIllf3epmAYt2Dp4yfkTYUb4ZD6iP4wXAPPxbVcdvnFlTkb1WWxepDQWEK0ZnJ DdHTf9hFKKfJXwRbAL+d2nhj9COfiqZTkRGXFHBGWJdrkZCml1PKVsoRHMbTyLWawLaE n4Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:subject:from:to:list-unsubscribe:message-id:sender :date:dkim-signature:dkim-signature; bh=x0ZMw0I1WGGyY0iAfLKkcp2ORKx8f+9epj5KYAQTyWU=; b=lXQb+EZaBxgknyxAWxy1uCfAcr8CBw1/RGTNxWuPHSsWdSgdOM84UfHTtU390PQkcz ABGH6ldkIjusniYW7qSLHwE7rMmninpcjukS+DPwSzruT2JRyHwtVFxjOTIuI/w3v/ef Q3GBbyK+kOmkijK1yJwAKmw9yK0iRNF4sC6aXy2oJdOEtLZeZL07bbs+AkSDu6hN9XR0 QjYQgLZcTH7Fh+rnysHtgI907AW+jqJwFS0nC30f3L/cXrsMSvwFWzEKxVLhhmpY0HMN 8BBNxyEGgBPSzeZU3yZk0Xtsnrg8q4nbs8dw74hzasgBEEad4GMIHnOTP2CepFz6wIIw Gsag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openprescribing.net header.s=pic header.b=djAwbAx+; dkim=pass header.i=@mailgun.org header.s=mg header.b=xrT0w8Sl; spf=pass (google.com: domain of bounce+722b84.3c4791-ebmdatalab17=gmail.com@openprescribing.net designates 198.61.254.23 as permitted sender) smtp.mailfrom="bounce+722b84.3c4791-ebmdatalab17=gmail.com@openprescribing.net" Return-Path: bounce+722b84.3c4791-ebmdatalab17=gmail.com@openprescribing.net Received: from so254-23.mailgun.net (so254-23.mailgun.net. [198.61.254.23]) by mx.google.com with UTF8SMTPS id x12-v6si1616172ith.71.2018.08.30.11.10.12 for ebmdatalab17@gmail.com (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 11:10:12 -0700 (PDT) Received-SPF: pass (google.com: domain of bounce+722b84.3c4791-ebmdatalab17=gmail.com@openprescribing.net designates 198.61.254.23 as permitted sender) client-ip=198.61.254.23; Authentication-Results: mx.google.com; dkim=pass header.i=@openprescribing.net header.s=pic header.b=djAwbAx+; dkim=pass header.i=@mailgun.org header.s=mg header.b=xrT0w8Sl; spf=pass (google.com: domain of bounce+722b84.3c4791-ebmdatalab17=gmail.com@openprescribing.net designates 198.61.254.23 as permitted sender) smtp.mailfrom="bounce+722b84.3c4791-ebmdatalab17=gmail.com@openprescribing.net" DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=openprescribing.net; q=dns/txt; s=pic; t=1535652612; h=Content-Type: Mime-Version: Subject: From: To: List-Unsubscribe: Message-Id: Sender: Date: X-Feedback-Id; bh=x0ZMw0I1WGGyY0iAfLKkcp2ORKx8f+9epj5KYAQTyWU=; b=djAwbAx+GwxcsXKlSHPSFTJ6y2t3pR4itkEIphnvR0rzfU1Cyy4GPvJ/7ABiSBeoxVR9y/WU eVBJAJMntIfritTzJfacd5SxIKBPlZZic9f48M3NMqHTwfiJtOE5CxFZUBrFE+HF5C0g92R6 N5fCcx8RVVysa0d7TfjmZtOIuDs= DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mailgun.org; q=dns/txt; s=mg; t=1535652612; h=Content-Type: Mime-Version: Subject: From: To: List-Unsubscribe: Message-Id: Sender: Date: X-Feedback-Id; bh=x0ZMw0I1WGGyY0iAfLKkcp2ORKx8f+9epj5KYAQTyWU=; b=xrT0w8SlxzFKWGQIhzfzsoOaWdl2tpsEHkj4po7LjXKe7AjNj6xAD37MF355s/ClDvgroC/h pTh+ORbk6/LRbDZ6DEujeRk372Z2+VljThEtX5vdAcgetOu4ny9Pm7gkkEfwCp5GRhrVGoPH HG4gS0CkfgF+OxTcLEtWE+MQNUM= X-Feedback-Id: 57b181f463badc5f3f12ec35:mailgun X-Mailgun-Sending-Ip: 198.61.254.23 X-Mailgun-Sid: WyI1YmRmNiIsICJlYm1kYXRhbGFiMTdAZ21haWwuY29tIiwgIjNjNDc5MSJd Received: by luna.mailgun.net with HTTP; Thu, 30 Aug 2018 18:10:10 +0000 Date: Thu, 30 Aug 2018 18:10:10 +0000 Sender: feedback@openprescribing.net X-Mailgun-Variables: {"email_id": "/email/monthly alert 2018-08-30/dashboard-alerts/1353", "campaign_name": "monthly alert 2018-08-30", "subject": "Your monthly update about NHS Oxfordshire CCG", "campaign_source": "dashboard-alerts"} Message-Id: 20180830180940.4417.58317@largeweb2.ebmdatalab.net List-Unsubscribe: https://openprescribing.net/bookmarks/79da24cba3e34933809bf056320937ef X-Mailgun-Tag: 2018-06-01 X-Mailgun-Tag: measures X-Mailgun-Tag: monthly_update To: ebmdatalab17@gmail.com From: feedback@openprescribing.net Subject: Your monthly update about NHS Oxfordshire CCG Mime-Version: 1.0 Content-Type: multipart/related; boundary="b9b3fd457e5044da8dc866ca77ca17ea"

--b9b3fd457e5044da8dc866ca77ca17ea Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="435bda9fe5a2456bb187403e3f38c56b"

--435bda9fe5a2456bb187403e3f38c56b Content-Type: text/plain; charset="utf-8" Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable

=20 =20

|

Hello!

Welcome to your monthly update about NHS Oxfordshire CCG. This is an experimental new service from OpenPrescr= ibing and we are keen for feedback: just reply to this email.

We've found four prescribing measures where this CCG is getting worse, and = nine measures where it is doing well. We've also found one prescribing meas= ure where there are some potential cost savings. Note that there can someti= mes be good reasons why one CCG is an outlier, and you should interpret the= data thoughtfully: these are measures, not indicators.

Prescribing measures which are getting worse

In comparison with other CCGs, we found that this CCG slipped considerably = on Silver dressings: =20 =20 It also slipped:

Possible savings

We looked at all the measures where this organisation could have saved at l= east =C2=A31,000 in the last six months. We found that if it had prescribed= in line with the average CCG, it could have saved about =C2=A320,000 o= n High-cost ARBs.

Best-case possible savings

We compared this CCG's spending with the best-performing 10% on all the are= as we track. If it prescribed as well as those CCGs, it could save around = =C2=A360,000**. Here's a list of measures, sorted by potential cost savin= gs.=20

Best prescribing measures

Over the last three months, we found that this CCG was in the best 10% on = High dose inhaled corticosteroids.=20

It was also in the best 10% on:

Prescribing measures which are getting better

In comparison with other CCGs, we found that this CCG improved moderately o= n Antibiotic stewardship: prescribing of trimethoprim vs nitrofurantoin.=20

It also improved:

Prescribing measures which are outliers

There are some areas where there is disagreement about whether higher, or lower, is better. Nonetheless it is interesting to know when an organisatio= n is very different from standard prescribing behaviour.

Over the last three months, we found that this CCG was in the top or bottom= 10% on Prescribing of pregabalin: =20 =20 It was also in the top or bottom 10% on Prescribing of pregabalin (total m= g).=20

We found that over the last 4 months this CCG moved slightly on Direct Ora= l Anticoagulants (DOACs).= =20

It also changed:

Achieved savings

Over the past 6 months, by prescribing better than the median, this CCG sav= ed around:

These alerts are still experimental, so if you see things that don't make sense, then please let us know by replying to this email. =20 =20 --- =20 =20 =20

=20 =20

|

Don't want these emails any more? Unsubscribe. =20 =20 --- =20 =20 =20

--435bda9fe5a2456bb187403e3f38c56b Content-Type: text/html; charset="utf-8" Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable

Your monthly alert from OpenPrescribing
=20

Hello!

Welcome to your monthly update about NHS Oxfordshire C= CG. This is an experimental new service from OpenPrescribing and we are= keen for feedback: just reply to this email.

We've found four prescribing measures where this CCG = is getting = worse, and nine measures where it is doing well. We've also found one pre= scribing measure where there are some potential cost savings. Note that the= re can sometimes be good reasons why one CCG is an outlier, and you should = interpret the data thoughtfully: these are measures, not indicators. =20 =20

Prescribing measures which are getting worse

=20 =20 In comparison with other CCGs, we found that this CCG slipped con= siderably on Silver dressings:

=20 =20 =20 =20 It also slipped:

=20 =20 =20 =20 =20 =20

Possible savings

We looked at all the measures where this organisa= tion could have saved at least =C2=A31,000 in the last six months. =20 We found that if it had prescribed in line with the average CCG, it c= ould have saved about =C2=A320,000 on High-cost ARBs.

=20 =20 =20

Best-case possible savings

We compared this CCG's spending with the best-p= erforming 10% on all the areas we track. If it prescribed as well as those= CCGs, it could save around =C2=A360,000. Here's a list of measures, sorted by potential = cost savings.

=20 =20

Best prescribing measures

=20 =20

Over the last three months, we found that thi= s CCG was in the best 10% on High dose inhaled corticosteroids. =20 =20 =20

It was also in the best 10% on: =20 =20 =20 =20 =20

Prescribing measures which are getting better

=20 =20

In comparison with other CCGs, we found tha= t this CCG improved moderately on Antibiotic stewardship: pr= escribing of trimethoprim vs nitrofurantoin. =20 =20 =20 =20

It also improved: =20 =20 =20 =20 =20

Prescribing measures which are outliers

There are some areas where there is disagreement about whether higher, = or lower, is better. Nonetheless it is interesting to know when an organisa= tion is very different from standard prescribing behaviour. =20 =20 =20 =20

Over the last three months, we found that t= his CCG was in the top or bottom 10% on Prescribing of pregabalin:

=20 =20 =20 It was also in the top or bottom 10% on Prescribing= of pregabalin (total mg). =20 =20 =20 =20 =20 =20

We found that over the last 4 months this CCG moved s= lightly on Direct Oral Anticoagulants (DOACs). =20 =20 =20 =20

It also changed: =20 =20 =20 =20 =20

Achieved savings

=20 Over the past 6 months, by prescribing better than the median, this CCG= saved around: =20 =20

These alerts are still experimental, so if you see = things that don't make sense, then please let us know by replying to this e= mail.

Don't want = these emails any more? Unsubscribe.

3D""

--435bda9fe5a2456bb187403e3f38c56b-- --b9b3fd457e5044da8dc866ca77ca17ea Content-Transfer-Encoding: base64 Content-Id: 20180830180954.4417.93710.img@largeweb2.ebmdatalab.net Content-Disposition: inline; filename="20180830180954.4417.93710.img@largeweb2.ebmdatalab.net" Content-Type: image/png; name="20180830180954.4417.93710.img@largeweb2.ebmdatalab.net" Mime-Version: 1.0

--b9b3fd457e5044da8dc866ca77ca17ea Content-Transfer-Encoding: base64 Content-Id: 20180830181009.4417.72120.img@largeweb2.ebmdatalab.net Content-Disposition: inline; filename="20180830181009.4417.72120.img@largeweb2.ebmdatalab.net" Content-Type: image/png; name="20180830181009.4417.72120.img@largeweb2.ebmdatalab.net" Mime-Version: 1.0

--b9b3fd457e5044da8dc866ca77ca17ea--

sebbacon commented 6 years ago

We can see that the image attachments were blank:

--435bda9fe5a2456bb187403e3f38c56b--
--b9b3fd457e5044da8dc866ca77ca17ea
Content-Transfer-Encoding: base64
Content-Id: <20180830180954.4417.93710.img@largeweb2.ebmdatalab.net>
Content-Disposition: inline; filename="20180830180954.4417.93710.img@largeweb2.ebmdatalab.net"
Content-Type: image/png; name="20180830180954.4417.93710.img@largeweb2.ebmdatalab.net"
Mime-Version: 1.0

--b9b3fd457e5044da8dc866ca77ca17ea
Content-Transfer-Encoding: base64
Content-Id: <20180830181009.4417.72120.img@largeweb2.ebmdatalab.net>
Content-Disposition: inline; filename="20180830181009.4417.72120.img@largeweb2.ebmdatalab.net"
Content-Type: image/png; name="20180830181009.4417.72120.img@largeweb2.ebmdatalab.net"
Mime-Version: 1.0

--b9b3fd457e5044da8dc866ca77ca17ea--
evansd commented 6 years ago

As an update to this, while sending the July alerts I received one for Lambeth which had working images and one for Oxfordshire which had broken images.

sebbacon commented 5 years ago

This is going to be tricky to debug.

There were two empty inline image attachments in the email above, both for measures.

Here's the code that does the attaching:

https://github.com/ebmdatalab/openprescribing/blob/41d430a9d3a277a0f1566de36c5987ce687c1ebd/openprescribing/frontend/views/bookmark_utils.py#L474-L489

It:

  1. Runs phantomjs as a subprocess to write an image to a file at a known location
  2. If there's no error, attaches the file

Given a file has been attached, that means the phantomjs script completed with a zero exit code, but wrote nothing to the file.

Success for the phantomjs script entails the measure div being visible, and then clipping a screen capture:

https://github.com/ebmdatalab/openprescribing/blob/41d430a9d3a277a0f1566de36c5987ce687c1ebd/openprescribing/frontend/management/commands/grab_chart.js#L100-L114

Given there's a catch-all exception handler there, it seems most likely that the clipping part failed for some reason. That would feasibly result in a file descriptor being opened and closed without any data being written to it.

I'm not sure what the best course of action would be here. Working out how to capture the console logging to a log file could be a start. Any ideas @evansd or @inglesp?

inglesp commented 5 years ago

What happens if we don't catch the exception?

sebbacon commented 5 years ago

Good question! Probably nothing but I'm not sure. Probably worth finding out.

evansd commented 5 years ago

Oh man, this is bringing back bad memories. I have already lost substantial portions of my life to debugging PhantomJS issues.

I'd say a first step would be to add a check to the Python code so that we only attach a file if it has some bytes in it. That would at least stop us sending out broken emails.

From memory, the failures seem not to be completely random (I think Oxfordshire CCG has repeatedly had problems) so I think the next step would be to try to reliably reproduce the issue in staging.

Longer term we should move off PhantomJS, which used to be the only game in town but has now been far superseded by headless Chrome.