Problem/Motivation
Some of the webforms we use on our site include uploaded documents/images. In the submission email we include a link to the uploaded file/image so the recipient can login, click the link and access the file.
Until recently (last couple of weeks) this worked fine. Now however the reference to the link no longer includes the real sid value but instead the placeholder text '_sid_'. As a result the file can't be accessed by clicking the link in the email since the link is incorrect.
This is what we used to have (and would like):
domain/system/files/webform/test_form/797/document.pdf
This is what we see now:
domain/system/files/webform/test_form/_sid_/document.pdf
The files are successfully stored in the a folder for the corresponding form with a sid value and the files can be also be accessed through the submissions page on the webform as expected.
Steps to reproduce
Create a simple form with a file upload
Edit the File field and under Advanced set the Submission display is set to Link or URL
Create an email handler to send the form to you on submission and include:
[webform_submission:values]
[webform_submission:sid]
Send a Test email
The resulting email will include the correct sid value for the [webform_submission:sid] but the URL of the file will have the placeholder '_sid_' instead of the real value.
Proposed resolution
Force webform submission attachments to be loaded from the DB.
Comment | File | Size | Author |
---|---|---|---|
#52 | 3175525-51-6.2.x.patch | 1.17 KB | gordon |
#47 | 3175525-47-stale-file-attachment-cache.patch | 770 bytes | sime |
#31 | 3175525-31.patch | 1.35 KB | jrockowitz |
|
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI am not able to replicate this issue using the attached webform.
Please provide a webform that can be used to replicate this issue.
Comment #3
skyhawk669 CreditAttribution: skyhawk669 commentedI am having the same issue. It worked well until today.
I have tested the attached webform and it also exhibits the problem on my live server. My test server is working fine, both with my forms as well as the attached form.
It sends an email with "_sid_" in the file URL instead of the actual sid. The weird thing is that if I go to the results page and resend the submission, then the URL is correct. It only happens during the initial email upon submitting the form.
I will be going over all the changes that have happened over the last few days and try to figure out what could be causing that issue on the live server but not the test server (they both have the same module versions installed).
Comment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe uploaded file's
_sid_
is replaced via\Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::postSave
which calls\Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::addFiles
The email is built and sent via
\Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::postSave
Finally,
WebformManagedFileBase::postSave
is called beforeEmailWebformHandler::postSave
@see \Drupal\webform\WebformSubmissionStorage::doPostSave
I am not seeing any explanation for this regression and I can't reproduce it.
What version of Drupal and Webform are you using?
The ticket's version was currently set 8.x-5.2 but I am going to assume the issue is in latest dev release.
Comment #5
namscott CreditAttribution: namscott commentedI am currently running Drupal 8.9.6 with Webform 5.22. But the problem started the release before, so still on 8.9.6 but with Webform5.21.
Comment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe only change in the 5.22 release that could possibly cause this issue is #3173856: Sort handlers with the same weight by the handlers_id but this change has no impact on the triggering of the ::postSave callbacks.
Comment #7
skyhawk669 CreditAttribution: skyhawk669 commentedI am having the issue on Drupal 8.9.6 -8.9.7, using Webform 5.22, I tried Webform 6, same thing. Since the issue does not exist on my test server, there must be a setup difference between the two that I have not documented.
Thank you for explaining the process, I will do some debugging and see if I can figure out what is going on.
Comment #8
namscott CreditAttribution: namscott commentedI think this may also be related, but I've set the 'Sanitize file name' setting and the link in the email includes the non-sanitized file name. But the sanitized filename is what is saved in the correct sid folder in the private folder. If this is something different I can open another issue.
This is the line fro the email with the file set to display as URL:
document
http://local.vm/system/files/webform/test_form/_sid_/5th-grade%20math-gr...
I tested the webform provided in #2 on my local system (no sanitization in this case) with the same outcome:
file
http://local.vm/system/files/webform/issue_3175525/_sid_/5th-grade%20mat...
Comment #9
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI don't think this santizing the file name is related to this issue.
Comment #10
namscott CreditAttribution: namscott commentedI only wonder because the sanitization is actually working. It's just in the email it doesn't show the sanitized version of the name. It's like the email is sent before the file processing has finished.
Comment #11
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented#4 documents that the file should uploaded, sanitized, and renamed before email is sent.
Comment #12
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI am bumping the priority to Major.
Comment #13
namscott CreditAttribution: namscott commentedI setup a new system to provide access for testing and when I tested the form it worked. This two systems have the same exact versions/setup for Drupal and Webform but they are different on the PHP/OS level.
The working system is running 7.3.18-1+ubuntu18.04.1+deb.sury.org+1 on Ubuntu 18.04.4 LTS.
The system having trouble is 7.3.20 on CentOS Linux 7 (Core)
Comment #14
skyhawk669 CreditAttribution: skyhawk669 commentedI have been chasing my tail trying to figure out what might be going on. All I have found so far is that the files are getting moved and renamed correctly, but when the tokens are being replaced and the file entity is loaded, it contains the old info before the move.
If for example if at the very end of \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::addFiles, I reload the file (using $this->entityTypeManager->getStorage('file')->load($fids[0])) it still outputs the URI/name before the changes were made.
If I do a database query at this same spot, it pulls the correct information, so I figured maybe it was a problem with the static cache not getting cleared? But it made no difference when I forced it to clear.
If I go to the submission page and resend the email, then the link to the file in the email is working properly, so at that stage the token replace function is able to load the file entity with the correct info.
I am not sure what could be causing this at this stage, considering I had not changed or upgraded anything when the error started happening.
Comment #15
skyhawk669 CreditAttribution: skyhawk669 commentedSorry, didn't mean to change the priority.
Comment #16
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@skyhawk669 Does the issue go away if you download grade from 5.22 to 5.21?
Comment #17
skyhawk669 CreditAttribution: skyhawk669 commented@jrockowitz I currently am on 6.0.0-alpha20. I was on 5.22 originally, but I had upgraded just in case that fixed it, which it did not. Is it possible to downgrade back down to 5.21?
I have not been able to reproduce the problem on any of my test servers, so I assume the issue must be outside of Webform, or some sort of interaction with another system. I do have memcached running on production but not on my test server, I will go ahead an try this.
Comment #18
skyhawk669 CreditAttribution: skyhawk669 commentedOK, after installing memcache 2.2 on my test server I can reproduce the problem! @namscott are you using any sort of caching as well?
Comment #19
namscott CreditAttribution: namscott commentedWe are running memcache (Memcached v3.1.5) as well as varnish (on production only). I do have varnish installed on my local but not running and I'm still seeing the issue with varnish not running so I thought it wouldn't be a factor. Both memcache and varnish are not enabled on my test system which is working fine.
Comment #20
skyhawk669 CreditAttribution: skyhawk669 commentedI use memcached and varnish on production as well. I enabled memcached on my test server and it now exhibits the same issue. For me, the problem started after upgrading to drupal/memcache 2.2. Downgrading to 2.1 solved the issue on my server. This bug is being caused by this change: https://www.drupal.org/project/memcache/issues/2996615
So it looks like something that needs to be fixed by the memcache module maintainers, it is not a Webform issue.
Comment #21
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI can was able to replicate this issue when enabling and configuring Memcache 2.2.
I am not sure if the Webform module can provide a workaround.
We could warn people using Memcache 2.2 and assume the issue will solved in Memcache 2.3
Comment #22
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedResetting the single file cache did not work for me but resetting the entire file entities cache does solve the problem but this is not a great solution.
Comment #23
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@skyhawk669 Thanks for figuring out the source of this issue.
Comment #24
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedAttached is a slightly better patch but using
\Drupal::entityTypeManager()->getStorage('file')->resetCache($fids);
does not work as expected.Comment #25
namscott CreditAttribution: namscott commentedThanks to both of you for figuring out the source of the problem.
Comment #26
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedSince over 8000 sites have already upgrade to Memcache 2.2. The only thing that I think we can do is warn users about this major regression via Drupal's Status report (/admin/reports/status).
Comment #28
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedAdding a warning is our only option, so I committed the patch.
Otherwise this issue needs to be addressed via #3176519: Uploaded files not linking correctly in emails sent through Webform module after upgrading to memcache 2.2
Comment #29
jibranFWIW, the following patch fixed the issue for a client site using CloudFront instead of Memcache.
Comment #30
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe patch seems like the right solution. Let's see if all tests are still passing.
Comment #31
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedAttached patch changes
to
Comment #32
jibranYeah, that is a good idea. We need to revert #26 so NW for that. Do you think we can add some tests for this?
Comment #33
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI am not sure how much test coverage we can add and maybe it is not absolutely needed.
The patch makes sense to me.
Comment #34
jibranYeah, I had the same idea. I think #26 can be removed on commit so setting it to RTBC.
Comment #35
jibranAdded proposed resolution to IS.
Comment #38
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #40
jedgar1mx CreditAttribution: jedgar1mx commentedI get an error when applying #31 to version 6.0
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2021-01-14/3175525-31.patch
Comment #41
jedgar1mx CreditAttribution: jedgar1mx commenteddouble post error sorry
Comment #42
JosephAM CreditAttribution: JosephAM commentedI'm still experiencing this issue, even after the patch.
Drupal: 8.9.13
Memcache module: 2.2
Webform: 8.x-5.12
I wondered if the patch + other updates in 8.x-5.x might have fixed it, but even after removing the patch and upgrading to 8.x-5.24 (which contains the patched code), I am still experiencing the _sid_ problem. Not only is this affecting links to files, but also attachments via Mail System + Swiftmailer.
FWIW, here are the bins I have configured for memcache:
$settings['cache']['bins']['bootstrap'] = 'cache.backend.memcache';
$settings['cache']['bins']['discovery'] = 'cache.backend.memcache';
$settings['cache']['bins']['config'] = 'cache.backend.memcache';
$settings['cache']['bins']['default'] = 'cache.backend.memcache';
$settings['cache']['bins']['render'] = 'cache.backend.memcache';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.memcache';
$settings['cache']['default'] = 'cache.backend.memcache';
Comment #43
ayalon CreditAttribution: ayalon at Liip commentedWe also still have the same issue. The upload is working, but the issue remains in the mail template. Downgrading to memcache 2.1 solves the issue.
Comment #44
peonboyos CreditAttribution: peonboyos commentedYes, same here.
It's still happening
Drupal: 8.9.13
Memcache module: 2.2
Webform: 8.x-5.24
Downgrade to memcache 2.1 fix the issue.
Comment #45
didaka CreditAttribution: didaka for Bright Solutions GmbH commentedSame here. I had to downgrade the memchace module. The issue should be reopened.
Comment #46
richardbporter CreditAttribution: richardbporter as a volunteer commentedYes still happening on Drupal 9.1.4, webform 6.0.1 and Memache 2.2. I'm not familiar with this functionality but in debugging it seems like
WebformManagedFileBase::getFileDestinationUri
replaces the_sid_
string in the destination correctly so I'm confused why its still in the email body.Comment #47
simeThe upgrade failed for us. We noticed the patch that we were using differs to what was applied to the module. This patch fixes it for us.
Comment #48
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedIf
$this->entityTypeManager->getStorage('file')->resetCache();
is called the file entity cache will be reset with every file upload which could impact a website's performance.I think this issue was addressed via https://www.drupal.org/project/memcache/releases/8.x-2.3
Comment #49
simeWe don't use memcache. We use redis if that helps.
We have not dived into why this is still an issue for us, but for now that patch keeps us running.
Comment #50
richardbporter CreditAttribution: richardbporter as a volunteer commentedUpdating memcache to 8.2.3 fixed it for us.
Comment #51
jedgar1mx CreditAttribution: jedgar1mx commentednew
memcache
version fixes issueComment #52
gordon CreditAttribution: gordon at Heydon Consulting for Department of Customer Service, NSW commentedI rerolled the patch to apply to 6.2